Main Menu
collapse

Simple Portal Archived Forum

This is an Archive Forum.

The content in this forum may be out-of-date or have been superseded by newer information, and links in forum pages to other sites may not work.
This forum contains archives for future reference.

Visit our thread at Simple Machines Forum for current support.

SMF 2.1 users: EhPortal is a ported version of Simple Portal specifically designed for the SMF 2.1 branch.
Please visit web-develop.ca to download EhPortal and for its support.

User Info

Welcome Guest.
Please log in.

Who's Online

  • Dot Guests: 738
  • Dot Hidden: 0
  • Dot Users: 0

There aren't any users online.

Recent Posts

Adding Forums Button to Nav bar by jirapon
[August 01, 2019, 09:07:12 AM]


Re: Board Icons by ♦ Ninja ZX-10RR ♦
[July 30, 2019, 04:03:41 PM]


MOVED: Czech translation???? by ♦ Ninja ZX-10RR ♦
[July 30, 2019, 03:04:51 PM]


Board Icons by jirapon
[July 30, 2019, 07:28:44 AM]


Re: Thankyou Simpleportal, by ♦ Ninja ZX-10RR ♦
[July 29, 2019, 09:41:29 AM]


Blocks speak! Do you have an interest in getting more blocks - or even making your own? The Blocks Board is for you!

Help edit code

Started by Dylert, November 21, 2013, 05:56:41 PM

Previous topic - Next topic

0 Members and 2 Guests are viewing this topic.

Dylert

Hello! I found this code which makes a nice recent topics block. It doesn't include board-name and read/posts. How can I add those two columns to the block?

$num_recent = 25; // HOW MANY RECENT TOPICS TO OUTPUT?
  $include_boards = null; // IF ALL BOARDS null | IF SOME BOARDS array( ID1, ID2, ID3)
 
 
 
  // code, code, code and some more code bahhh!
  global $smcFunc, $scripturl, $context, $settings, $db_prefix, $user_info;
 
  if (is_array($include_boards) || (int) $include_boards === $include_boards)
{
$include_boards = is_array($include_boards) ? $include_boards : array($include_boards);
}
elseif ($include_boards != null)
{
$output_method = $include_boards;
$include_boards = array();
}

$topics_result = $smcFunc['db_query']('', '
    SELECT m.poster_name, m.poster_time, m.id_msg, t.id_member_updated, m.subject, m.body, m.id_topic, b.name, b.id_board, t.id_last_msg, u.avatar, g.online_color, ' . ($user_info['is_guest'] ? '1 AS is_read, 0 AS new_from' : '
IFNULL(lt.id_msg, IFNULL(lmr.id_msg, 0)) >= m.id_msg_modified AS is_read,
IFNULL(lt.id_msg, IFNULL(lmr.id_msg, -1)) + 1 AS new_from') . '
    FROM {db_prefix}topics AS t
    INNER JOIN {db_prefix}boards AS b ON (t.id_board = b.id_board)
    INNER JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_last_msg)
    LEFT JOIN {db_prefix}members AS u ON (t.id_member_updated = u.id_member)
    LEFT JOIN {db_prefix}membergroups AS g ON (g.id_group = CASE WHEN u.id_group = 0 THEN u.id_post_group ELSE u.id_group END)' . (!$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})' : '') . ' 
    WHERE m.approved=1' . (empty($include_boards) ? '' : '
AND b.id_board IN ({array_int:include_boards})') . '
    ORDER BY t.id_last_msg DESC
    LIMIT ' . $num_recent,
array(
'current_member' => $user_info['id'],
'include_boards' => empty($include_boards) ? '' : $include_boards,
)   
    );
$topics = array();
while ($row_topics = $smcFunc['db_fetch_assoc']($topics_result))
{
    $topics[] = array(
       'topic' => $row_topics['id_topic'],
       'poster' => '<a style="color: ' . $row_topics['online_color'] . ';" href="' . $scripturl . '?action=profile;u=' . $row_topics['id_member_updated'] . '">' . $row_topics['poster_name'] . '</a>',
       'link' => '<a title="In&nbsp;' . $row_topics['name'] .'" href="' . $scripturl . '?topic=' . $row_topics['id_topic'] . '.msg' . $row_topics['id_last_msg'] . ';topicseen#new">' . $row_topics['subject'] . '</a>',
       'href' => $scripturl . '?topic=' . $row_topics['id_topic'] . '.msg' . $row_topics['id_last_msg'] . ';topicseen#new',
  'time' => timeformat($row_topics['poster_time']),
  'new' => !empty($row_topics['is_read'])
    );
}
$smcFunc['db_free_result']($topics_result);
echo '
<div class="tabsmenucontent" style="padding: 2px">
<table border="0" width="100%" cellspacing="1" cellpadding="2" class="bordercolor">
<tr class="titlebg">
                 <td valign="middle">Topic</td>
<td valign="middle">Poster</td>
<td valign="middle">Time</td>
<td valign="middle"></td>
</tr>';

foreach ($topics as $topic)
{
echo '
<tr>
<td class="windowbg" valign="middle">', $topic['link'];

// new log! What a headache!
if (!$topic['new'] && $context['user']['is_logged'])
echo '
<a href="', $scripturl, '?topic=', $topic['topic'], '.from', $topic['time'], '#new"><img src="', $settings['images_url'], '/', $context['user']['language'], '/new.gif" alt="new" border="0" /></a>';

echo '
</td>
<td class="windowbg2" valign="middle">', $topic['poster'], '</td>
<td class="windowbg2" valign="middle">', $topic['time'], '</td>
<td class="windowbg2" valign="middle">';

if ($settings['images_url'] != $settings['theme_url'] . '/images' || file_exists($settings['theme_dir'] . '/images/icons/last_post.gif'))
echo '
<a href="', $topic['href'], '"><img src="', $settings['images_url'], '/icons/last_post.gif" alt="Last Post" title="Last Post" border="0" style="float: right;" /></a>';
}

echo '
</td>
</tr>
</table>
</div>';