I think, there is a problem with this custom php block, which might be caused by php 8...
Spuds and Emanuele were writing this code once for our forum.
I use it in 3 variants on forum and in portal.
global $context, $settings, $scripturl, $txt, $user_info, $modSettings, $posts, $color_profile;
$db = database();
$exclude_boards = null;
// Number of items to show
$num_recent = 25;
// Show the body preview on hover
$show_preview = true;
// Show the body preview text in the block
$show_body = false;
// Number of characters to show in the preview, 0 is all
$preview_char = 128;
// First or last message for the preview
$preview_last = false;
if ($exclude_boards === null && !empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0)
$exclude_boards = array($modSettings['recycle_board']);
else
$exclude_boards = empty($exclude_boards) ? array() : $exclude_boards;
$stable_icons = array('xx', 'thumbup', 'thumbdown', 'exclamation', 'question', 'lamp', 'smiley', 'angry', 'cheesy', 'grin', 'sad', 'wink', 'moved', 'recycled', 'wireless');
$icon_sources = array();
foreach ($stable_icons as $icon)
$icon_sources[$icon] = 'images_url';
// If empty, no previews at all
if (empty($show_preview) && empty($show_body))
$preview_bodies = '';
// If 0 means everything
elseif (empty($preview_char))
$preview_bodies = ', ml.body AS last_body, mf.body AS first_body';
// else a SUBSTRING
else
$preview_bodies = ', SUBSTRING(ml.body, 1, ' . ($preview_char + 256) . ') AS last_body, SUBSTRING(mf.body, 1, ' . ($preview_char + 256) . ') AS first_body';
// Find all the posts in distinct topics. Newer ones will have higher IDs.
$request = $db->query('substring', '
SELECT
mf.subject,
ml.id_msg, ml.id_topic, ml.id_member, ml.poster_time,
b.id_board, b.name AS bName,
t.num_replies, t.num_views, t.id_first_msg, t.id_last_msg,
IFNULL(mem.real_name, ml.poster_name) AS poster_name, ' . ($user_info['is_guest'] ? '1 AS is_read, 0 AS new_from' : '
IFNULL(lt.id_msg, IFNULL(lmr.id_msg, 0)) >= ml.id_msg_modified AS is_read,
IFNULL(lt.id_msg, IFNULL(lmr.id_msg, -1)) + 1 AS new_from') . ', mf.smileys_enabled, mf.icon, mg.online_color' .
$preview_bodies . '
FROM {db_prefix}topics AS t
INNER JOIN {db_prefix}messages AS mf ON (mf.id_msg = t.id_first_msg)
INNER JOIN {db_prefix}messages AS ml ON (ml.id_msg = t.id_last_msg)
LEFT JOIN {db_prefix}boards AS b ON (b.id_board = mf.id_board)
LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = ml.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 = b.id_board AND lmr.id_member = {int:current_member})' : '') . '
LEFT JOIN {db_prefix}membergroups AS mg ON (mg.id_group = mem.id_group)
WHERE t.id_last_msg >= {int:likely_max_msg}
AND b.id_board = t.id_board' . (empty($exclude_boards) ? '' : '
AND b.id_board NOT IN ({array_int:exclude_boards})') . '
AND {query_wanna_see_board}' . ($modSettings['postmod_active'] ? '
AND t.approved = {int:is_approved}
AND ml.approved = {int:is_approved}' : '') . '
ORDER BY t.id_last_msg DESC
LIMIT {int:limit}',
array(
'current_member' => $user_info['id'],
'exclude_boards' => $exclude_boards,
'limit' => (int) $num_recent,
'is_approved' => 1,
'likely_max_msg' => $modSettings['maxMsgID'] - 35 * min($num_recent, 5),
'preview_char' => $preview_char,
)
);
$posts = array();
$color_ids = array();
while ($row = $db->fetch_assoc($request))
{
// Shorten and censor the body as needed
$row['body'] = '';
if (!(empty($show_preview) && empty($show_body)))
{
if (!empty($preview_char))
{
$row['body'] = strip_tags(strtr(parse_bbc($preview_last ? $row['last_body'] : $row['first_body'], false, $row['id_first_msg']), array('<br />' => "\n", ' ' => ' ')));
$row['body'] = Util::shorten_text($row['body'], !empty($modSettings['preview_characters']) ? $modSettings['preview_characters'] : $preview_char, true);
}
elseif (!empty($show_preview))
$row['body'] = strip_tags(strtr(parse_bbc($preview_last ? $row['last_body'] : $row['first_body'], false, $row['id_first_msg']), array('<br />' => "\n", ' ' => ' ')));
censorText($row['body']);
}
// Censor the subject.
$row['subject'] = preg_replace('/^' . preg_quote($txt['response_prefix']) . '/', '', $row['subject']);
censorText($row['subject']);
// Collect the color ids :)
$color_ids[$row['id_member']] = $row['id_member'];
if (empty($modSettings['messageIconChecks_disable']) && !isset($icon_sources[$row['icon']]))
$icon_sources[$row['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['icon'] . '.png') ? 'images_url' : 'default_images_url';
// Build the array.
$posts[] = array(
'board' => array(
'id' => $row['id_board'],
'name' => $row['bName'],
'href' => $scripturl . '?board=' . $row['id_board'] . '.0',
'link' => '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['bName'] . '</a>'
),
'topic' => $row['id_topic'],
'poster' => array(
'id' => $row['id_member'],
'name' => $row['poster_name'],
'href' => empty($row['id_member']) ? '' : $scripturl . '?action=profile;u=' . $row['id_member'],
'link' => empty($row['id_member']) ? $row['poster_name'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['poster_name'] . '</a>'
),
'subject' => $row['subject'],
'short_subject' => Util::shorten_text($row['subject'], 25),
'preview' => $row['body'],
'time' => standardTime($row['poster_time']),
'timestamp' => forum_time(true, $row['poster_time']),
'href' => $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . ';topicseen#new',
'link' => '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#new">' . $row['subject'] . '</a>',
'new' => !empty($row['is_read']),
'new_from' => $row['new_from'],
'icon' => '<img src="' . $settings[$icon_sources[$row['icon']]] . '/post/' . $row['icon'] . '.png" style="vertical-align: middle;" alt="' . $row['icon'] . '" />',
'views' => $row['num_views'],
'replies' => $row['num_replies'],
);
}
$db->free_result($request);
// Colorization
if (!empty($color_ids) && sp_loadColors($color_ids) !== false)
{
foreach ($posts as $key => $value)
{
if (!empty($color_profile[$value['poster']['id']]['link']))
$posts[$key]['poster']['link'] = $color_profile[$value['poster']['id']]['link'];
}
}
$context['recent_topics'] = $posts;
// Just return if we have no results
if (empty($posts))
return $txt['error_sp_no_posts_found'];
// Preview tips?
if (!empty($show_preview))
addInlineJavascript('
$(document).ready(function () {
$(".sp_custom_tr2").SiteTooltip({
hoverIntent: {
sensitivity: 10,
interval: 150,
timeout: 50
}
});
});', true);
echo '
<style>
.sp_custom_tr {display: table-cell; padding: 0 8px;border-bottom:1px dashed #6394BD;text-align: center;}
.sp_custom_tr1 {display: table-cell;border-bottom:1px dashed #6394BD;width:100%;}
.sp_custom_tr2 {font-weight: bold;}
</style>
<div>';
foreach ($posts as $post)
{
echo '
<div style="display: table-row">
<div class="sp_custom_tr centericon">
', $post['icon'], '
</div>
<div class="sp_custom_tr1" >
', $post['new'] ? '' : '<a href="' . $scripturl . '?topic=' . $post['topic'] . '.msg' . $post['new_from'] . ';topicseen#new" rel="nofollow"><span class="new_posts"> ' . $txt['new'] . '</span></a>', '
<a class="sp_custom_tr2" href="', $post['href'], '" title="', $post['preview'], '">', $post['subject'], '</a>';
echo '
<div class="smalltext">
', $txt['by'], ' ', $post['poster']['link'], ' ', $txt['in'], ' ', $post['board']['link'], '
</br />
', $post['time'], ' | ', $txt['views'], ': ', $post['views'], ' | ', $txt['replies'], ': ', $post['replies'], '
</div>';
if (!empty($show_body))
echo '
<div class="middletext">
', $post['preview'], '
</div>';
echo '
</div>
</div>';
}
echo '
</div>';
The small one on forum is still working proper. It displayes the time format this way and correct:
<div class="sp_custom_tr1" >
', $post['new'] ? '' : '<a href="' . $scripturl . '?topic=' . $post['topic'] . '.msg' . $post['new_from'] . ';topicseen#new" rel="nofollow"><span class="new_posts"> ' . $txt['new'] . '</span></a>', '
<a class="sp_custom_tr2" href="', $post['href'], '" title="', $post['preview'], '">', $post['subject'], '</a>';
echo '
<div class="smalltext">
', $txt['by'], ' ', $post['poster']['link'], ' ', $txt['in'], ' ', $post['board']['link'], ' - ', $post['time'], '
</div>';
But the "big one" in portal shows "Uhr" twice together with "today" and "yesterday". And it does tell "Zeitformat" ("time format") instead of the time. I don't understand why. Should it not be just the same like in the other portal block?
<div class="sp_custom_tr1" >
', $post['new'] ? '' : '<a href="' . $scripturl . '?topic=' . $post['topic'] . '.msg' . $post['new_from'] . ';topicseen#new" rel="nofollow"><span class="new_posts"> ' . $txt['new'] . '</span></a>', '
<a class="sp_custom_tr2" href="', $post['href'], '" title="', $post['preview'], '">', $post['subject'], '</a>';
echo '
<div class="smalltext">
', $txt['by'], ' ', $post['poster']['link'], ' ', $txt['in'], ' ', $post['board']['link'], '
</br />
', $post['time'], ' | ', $txt['views'], ': ', $post['views'], ' | ', $txt['replies'], ': ', $post['replies'], '
</div>';
On the smart phone of my friend this portal block shows the time correct....but not on my laptop.