Storman: unfortunately the sheer number of changes makes even doing that difficult (as discussed in plenty of other places)
As a mitigation technique, replace this code in that file:
if (!empty($context['user_rp_topics']))
{
$result = $smcFunc['db_query']('', '
SELECT id_msg, {db_prefix}messages.id_topic, id_member, poster_name, body, poster_time
FROM {db_prefix}messages INNER JOIN {db_prefix}topics
ON {db_prefix}messages.id_topic = {db_prefix}topics.id_topic
WHERE {db_prefix}topics.id_topic = {int:initial_display_id}
ORDER BY id_msg DESC
LIMIT 20',
array(
'initial_display_id' => $context['user_rp_topics'][0]['id_topic'],
)
);
while ($row = $smcFunc['db_fetch_assoc']($result))
{
if (!isset($memberContext[$row['id_member']]))
{
loadMemberData(array($row['id_member']), false, 'normal');
loadMemberContext($row['id_member']);
}
$context['user_rp_posts'][] = array(
'id' => $row['id_msg'],
'topic_id' => $row['id_topic'],
'poster' => $row['poster_name'],
'member_href' => $memberContext[$row['id_member']]['href'],
'avatar' => !empty($memberContext[$row['id_member']]['avatar']['href']) ? $memberContext[$row['id_member']]['avatar']['href'] : $settings['default_theme_url'] . '/images/default_ava.png',
'body' => parse_bbc($row['body']),
'time' => timeformat($row['poster_time']),
'can_modify' => $row['id_member'] === $context['user']['id'] || $context['user']['can_mod'] ? true : false
);
}
$smcFunc['db_free_result']($result);
$context['user_rp_posts'] = array_reverse($context['user_rp_posts']);
$context['initial_display_thread'] = $context['user_rp_topics'][0]['id_topic'];
}
if (!empty($context['user_rp_topics']))
{
$result = $smcFunc['db_query']('', '
SELECT id_msg, {db_prefix}messages.id_topic, id_member, poster_name, body, poster_time
FROM {db_prefix}messages INNER JOIN {db_prefix}topics
ON {db_prefix}messages.id_topic = {db_prefix}topics.id_topic
WHERE {db_prefix}topics.id_topic = {int:initial_display_id}
ORDER BY id_msg DESC
LIMIT 20',
array(
'initial_display_id' => $context['user_rp_topics'][0]['id_topic'],
)
);
$users_ids = array();
while ($row = $smcFunc['db_fetch_assoc']($result))
{
if (!isset($memberContext[$row['id_member']]))
$user_ids[] = $row['id_member'];
$context['user_rp_posts'][] = array(
'id' => $row['id_msg'],
'id_member' => $row['id_member'],
'topic_id' => $row['id_topic'],
'poster' => $row['poster_name'],
'body' => parse_bbc($row['body']),
'time' => timeformat($row['poster_time']),
'can_modify' => $row['id_member'] === $context['user']['id'] || $context['user']['can_mod'] ? true : false
);
}
$smcFunc['db_free_result']($result);
$context['user_rp_posts'] = array_reverse($context['user_rp_posts']);
$context['initial_display_thread'] = $context['user_rp_topics'][0]['id_topic'];
if (!empty($user_ids))
{
$user_ids = loadMemberData($user_ids, false, 'normal');
if (!empty($user_ids))
foreach ($user_ids as $id)
loadMemberContext($id);
}
foreach ($context['user_rp_posts'] as $k => $v)
{
$context['user_rp_posts'][$k]['member_href'] = empty($memberContext[$v['id_member']]['href']) ? '' : $memberContext[$v['id_member']]['href'];
$context['user_rp_posts'][$k]['avatar'] = !empty($memberContext[$v['id_member']]['avatar']['href']) ? $memberContext[$v['id_member']]['avatar']['href'] : $settings['default_theme_url'] . '/images/default_ava.png';
}
}
The error should be squelched by the fact that we're actually testing for the member's link before using it (which is what the error was) however I have the uncomfortable feeling that the template is going to assume it's actually a link even when a link may not be possible, so it may just be buggy - but it won't have a performance impact of any magnitude, certainly far less than it would otherwise.
The rest of the changes simply move the DB queries around a bit - if you're requesting 20 posts and have even 3 different authors (including the person whose profile it is), that's still going to generate 2 queries, whereas this should only generate 1 query regardless of how many different posters are being used.
I don't know who wrote this code originally but while it works, it's neither elegant nor efficient. The above is merely firefighting, as opposed to really figuring out how best to achieve what you want. You know it's problematic when I'm having trouble trying to figure out what the code's actually supposed to do (since I suspect there are side effects the author is not aware of)