TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

May 17, 2024, 09:30:19 AM

Login with username, password and session length
Members
  • Total Members: 3,886
  • Latest: Grendor
Stats
  • Total Posts: 195,189
  • Total Topics: 21,220
  • Online today: 59
  • Online ever: 3,540 (September 03, 2022, 01:38:54 AM)
Users Online
  • Users: 0
  • Guests: 29
  • Total: 29

"recent topics" in SMF style

Started by Lesmond, August 17, 2005, 12:01:38 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

dannbass

Quote from: J.A.Cortina on October 23, 2007, 03:38:56 PM
Hold on for a few days. I'm looking at implementing a version of this as a separate function. While not as 'convenient' as having it in a block/article, it makes a LOT more sense when its functionality will be called in more than one place/circumstance.

I don't mean to sound pushy or anything like it... but how is the progress? and what did you mean by having it as a separate function? like using it in a template, instead that in TinyPortal, and then having the a block with a simple command?

Thanks a lot!

jacortina

Like the ssi_recentTopics() is a separate function which can echo things out or return an array.

Personally, I use this code in a couple of spots (in an article with URL query arguments to put out different 'recent' lists, but also in a block with specific topic ID's set to act as a 'Global Announcement' block). So, rather than maintain code in multiple places, a single function can be called with only the argmument list to be dealt with.

I think I'm on the last bit of tweaking/major debugging, so I should be able to put it out soon.

In your case, with wanting to have a block with multiple instances of it, it would be a lot easier to:

set up args;
call function;

set up args;
call function;

set up args;
call function;

Rather than repeat the whole code block each time.

dannbass

Thanks! I thought of that... at least in theory, but not in practice... the other day I thought that why will I need to repeat the same whole code every time... but I need more practice with my php skills...

Thanks a lot! I really appreciate all the work that you have put into it!

mrzcn


catchpen

#374
Here's a version that incorporates the "Topic Rating" mod at SMF http://www.simplemachines.org/community/index.php?topic=25023.0
This must be installed first for this to work.  It shows the rating stars of each topic in a column instead of number of views. 
First try so let me know if there is anything wrong with code  ;)

$announce_topics = array( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ); // Topic ID's to be 'Announced' is where you put the topic ID #'s


global $context, $settings, $scripturl, $txt, $db_prefix, $ID_MEMBER, $user_info, $modSettings, $user_profile;

$exclude_boards = array(); // KEEP (to preserve variable declaration)
$ex_board_clause = !empty($exclude_boards) ? ' AND b.ID_BOARD NOT IN (' . implode(', ', $exclude_boards) . ')' : '';
$do_query = 1;

$announce_topics = array( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ); // Topic ID's to be 'Announced'
$heading = '<center> Latest Picks <center>';

$where_clause = 't.ID_TOPIC IN (' . implode(', ', $announce_topics) . ')';
$limit_clause = '';
$order_clause = 't.ID_LAST_MSG DESC';


$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';

$groupcolors = array();
$request = db_query("SELECT ID_GROUP, onlineColor FROM {$db_prefix}membergroups", __FILE__, __LINE__);
while ($row = mysql_fetch_assoc($request))
$groupcolors[$row['ID_GROUP']] = $row['onlineColor'];
mysql_free_result($request);

$topics = array();

if ($do_query == 1)
{
$request = db_query("
SELECT
ms.subject AS firstSubject, ms.posterTime AS firstPosterTime, ms.ID_TOPIC, t.ID_BOARD, b.name AS bname,
t.numReplies,rating,ms.ID_MEMBER AS ID_FIRST_MEMBER, ml.ID_MEMBER AS ID_LAST_MEMBER,
ml.posterTime AS lastPosterTime, IFNULL(mems.realName, ms.posterName) AS firstPosterName,
IFNULL(meml.realName, ml.posterName) AS lastPosterName,
mems.ID_GROUP as mems_group, meml.ID_GROUP as meml_group, mems.ID_POST_GROUP as mems_pgroup,
ml.subject AS lastSubject, b.memberGroups, meml.ID_POST_GROUP as meml_pgroup,
ml.icon AS lastIcon, ms.icon AS firstIcon, t.ID_POLL, t.isSticky, t.locked, ml.modifiedTime AS lastModifiedTime,
LEFT(ml.body, 384) AS lastBody, LEFT(ms.body, 384) AS firstBody,
ml.smileysEnabled AS lastSmileys, ms.smileysEnabled AS firstSmileys, t.ID_FIRST_MSG, t.ID_LAST_MSG,"
. ($user_info['is_guest'] ? '1 AS isRead, 0 AS new_from' : '
IFNULL(lt.ID_MSG, IFNULL(lmr.ID_MSG, 0)) >= ml.ID_MSG_MODIFIED AS isRead,
IFNULL(lt.ID_MSG, IFNULL(lmr.ID_MSG, -1)) + 1 AS new_from') . "
FROM ({$db_prefix}messages AS ms, {$db_prefix}messages AS ml, {$db_prefix}topics AS t, {$db_prefix}boards AS b)
LEFT JOIN {$db_prefix}members AS mems ON (mems.ID_MEMBER = ms.ID_MEMBER)
LEFT JOIN {$db_prefix}members AS meml ON (meml.ID_MEMBER = ml.ID_MEMBER)
LEFT JOIN {$db_prefix}log_topics AS lt ON (lt.ID_TOPIC = t.ID_TOPIC AND lt.ID_MEMBER = $ID_MEMBER)
LEFT JOIN {$db_prefix}log_mark_read AS lmr ON (lmr.ID_BOARD = t.ID_BOARD AND lmr.ID_MEMBER = $ID_MEMBER)
WHERE " . $where_clause . $ex_board_clause . "
AND t.ID_TOPIC = ms.ID_TOPIC
AND b.ID_BOARD = t.ID_BOARD" . (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? " AND b.ID_BOARD != $modSettings[recycle_board]" : '') . "
AND ms.ID_MSG = t.ID_FIRST_MSG
AND ml.ID_MSG = t.ID_LAST_MSG
AND " . $user_info['query_see_board'] . "
ORDER BY " . $order_clause . " " . $limit_clause, __FILE__, __LINE__);


$topic_ids = array();
while ($row = mysql_fetch_assoc($request))
{
if ($row['ID_POLL'] > 0 && $modSettings['pollMode'] == '0')
continue;

$topic_ids[] = $row['ID_TOPIC'];

// Clip the strings first because censoring is slow :/. (for some reason?)
$row['firstBody'] = strip_tags(strtr(parse_bbc($row['firstBody'], $row['firstSmileys'], $row['ID_FIRST_MSG']), array('<br />' => '
')));
if (strlen($row['firstBody']) > 128)
$row['firstBody'] = substr($row['firstBody'], 0, 128) . '...';
$row['lastBody'] = strip_tags(strtr(parse_bbc($row['lastBody'], $row['lastSmileys'], $row['ID_LAST_MSG']), array('<br />' => '
')));
if (strlen($row['lastBody']) > 128)
$row['lastBody'] = substr($row['lastBody'], 0, 128) . '...';

$row['lastSubject'] = $row['firstSubject'];
$row['lastBody'] = $row['firstBody'];

// Decide how many pages the topic should have.
$topic_length = $row['numReplies'] + 1;
if ($topic_length > $modSettings['defaultMaxMessages'])
{
$tmppages = array();
$tmpa = 1;
for ($tmpb = 0; $tmpb < $topic_length; $tmpb += $modSettings['defaultMaxMessages'])
{
$tmppages[] = '<a href="' . $scripturl . '?topic=' . $row['ID_TOPIC'] . '.' . $tmpb . ';topicseen">' . $tmpa . '</a>';
$tmpa++;
}
// Show links to all the pages?
if (count($tmppages) <= 5)
$pages = '« ' . implode(' ', $tmppages);
// Or skip a few?
else
$pages = '« ' . $tmppages[0] . ' ' . $tmppages[1] . ' ... ' . $tmppages[count($tmppages) - 2] . ' ' . $tmppages[count($tmppages) - 1];

if (!empty($modSettings['enableAllMessages']) && $topic_length < $modSettings['enableAllMessages'])
$pages .= '  <a href="' . $scripturl . '?topic=' . $row['ID_TOPIC'] . '.0;all">' . $txt[190] . '</a>';
$pages .= ' »';
}
else
$pages = '';

// We need to check the topic icons exist... you can never be too sure!
if (empty($modSettings['messageIconChecks_disable']))
{
// First icon first... as you'd expect.
if (!isset($icon_sources[$row['firstIcon']]))
$icon_sources[$row['firstIcon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['firstIcon'] . '.gif') ? 'images_url' : 'default_images_url';
// Last icon... last... duh.
if (!isset($icon_sources[$row['lastIcon']]))
$icon_sources[$row['lastIcon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['lastIcon'] . '.gif') ? 'images_url' : 'default_images_url';
}

$color_start = !empty($groupcolors[$row['mems_group']]) ? $groupcolors[$row['mems_group']] : '';
$color_last = !empty($groupcolors[$row['meml_group']]) ? $groupcolors[$row['meml_group']] : '';

// And build the array.
$topics[$row['ID_TOPIC']] = array(
'id' => $row['ID_TOPIC'],
'first_post' => array(
'id' => $row['ID_FIRST_MSG'],
'member' => array(
'name' => $row['firstPosterName'],
'id' => $row['ID_FIRST_MEMBER'],
'href' => $scripturl . '?action=profile;u=' . $row['ID_FIRST_MEMBER'],
'link' => !empty($row['ID_FIRST_MEMBER']) ? ('<a href="' . $scripturl . '?action=profile;u=' . $row['ID_FIRST_MEMBER'] . '" title="' . $txt[92] . ' ' . $row['firstPosterName'] . '">' . ( !empty($modSettings['MemberColorLink']) ? ( !empty($groupcolors[$row['mems_group']]) || !empty($groupcolors[$row['mems_pgroup']])  ? '<font color="'. ( !empty($groupcolors[$row['mems_group']]) ? $groupcolors[$row['mems_group']] : $groupcolors[$row['mems_pgroup']] ) . '">' : '' ) : '' )  . $row['firstPosterName'] . ((!empty($modSettings['MemberColorLink']) && ( !empty($groupcolors[$row['mems_group']]) || !empty($groupcolors[$row['mems_pgroup']]))) ? '</font>' : '' ) . '</a>' ) : $row['firstPosterName']
),
'time' => timeformat($row['firstPosterTime']),
'timestamp' => forum_time(true, $row['firstPosterTime']),
'subject' => $row['firstSubject'],
'preview' => $row['firstBody'],
'icon' => $row['firstIcon'],
'icon_url' => $settings[$icon_sources[$row['firstIcon']]] . '/post/' . $row['firstIcon'] . '.gif',
'href' => $scripturl . '?topic=' . $row['ID_TOPIC'] . '.0;topicseen',
'link' => '<a href="' . $scripturl . '?topic=' . $row['ID_TOPIC'] . '.0;topicseen">' . $row['firstSubject'] . '</a>'
),
'last_post' => array(
'id' => $row['ID_LAST_MSG'],
'member' => array(
'name' => $row['lastPosterName'],
'id' => $row['ID_LAST_MEMBER'],
'href' => $scripturl . '?action=profile;u=' . $row['ID_LAST_MEMBER'],
'link' => !empty($row['ID_LAST_MEMBER']) ? '<a href="' . $scripturl . '?action=profile;u=' . $row['ID_LAST_MEMBER'] . '" title="' . $txt[92] . ' ' . $row['lastPosterName'] . '">' . (!empty($modSettings['MemberColorLink']) ? ( !empty($groupcolors[$row['meml_group']]) || !empty($groupcolors[$row['meml_pgroup']]) ? '<font color="'. ( !empty($groupcolors[$row['meml_group']]) ? $groupcolors[$row['meml_group']] : $groupcolors[$row['meml_pgroup']] ) .'">' : '' ) : '' ) . $row['lastPosterName'] . ((!empty($modSettings['MemberColorLink']) && ( !empty($groupcolors[$row['meml_group']]) || !empty($groupcolors[$row['meml_pgroup']]))) ? '</font>' : '' ) . '</a>' : $row['lastPosterName']
),
'time' => timeformat($row['lastPosterTime']),
'timestamp' => forum_time(true, $row['lastPosterTime']),
'subject' => $row['lastSubject'],
'preview' => $row['lastBody'],
'icon' => $row['lastIcon'],
'icon_url' => $settings[$icon_sources[$row['lastIcon']]] . '/post/' . $row['lastIcon'] . '.gif',
'href' => $scripturl . '?topic=' . $row['ID_TOPIC'] . ($row['numReplies'] == 0 ? '.0' : '.msg' . $row['ID_LAST_MSG']) . ';topicseen#msg' . $row['ID_LAST_MSG'],
'link' => '<a href="' . $scripturl . '?topic=' . $row['ID_TOPIC'] . ($row['numReplies'] == 0 ? '.0' : '.msg' . $row['ID_LAST_MSG']) . ';topicseen#msg' . $row['ID_LAST_MSG'] . '">' . $row['lastSubject'] . '</a>'
),
'new' => $row['isRead'],
'new_from' => $row['new_from'],
'new_href' => $scripturl . '?topic=' . $row['ID_TOPIC'] . '.msg' . $row['new_from'] . ';topicseen#new',
'href' => $scripturl . '?topic=' . $row['ID_TOPIC'] . ($row['numReplies'] == 0 ? '.0' : '.msg' . $row['new_from']) . ';topicseen' . ($row['numReplies'] == 0 ? '' : 'new'),
'link' => '<a href="' . $scripturl . '?topic=' . $row['ID_TOPIC'] . ($row['numReplies'] == 0 ? '.0' : '.msg' . $row['new_from']) . ';topicseen#msg' . $row['new_from'] . '">' . $row['firstSubject'] . '</a>',
'is_sticky' => !empty($modSettings['enableStickyTopics']) && !empty($row['isSticky']),
'is_locked' => !empty($row['locked']),
'is_poll' => $modSettings['pollMode'] == '1' && $row['ID_POLL'] > 0,
'is_hot' => $row['numReplies'] >= $modSettings['hotTopicPosts'],
'is_very_hot' => $row['numReplies'] >= $modSettings['hotTopicVeryPosts'],
'is_posted_in' => false,
'icon' => $row['firstIcon'],
'icon_url' => $settings[$icon_sources[$row['firstIcon']]] . '/post/' . $row['firstIcon'] . '.gif',
'subject' => $row['firstSubject'],
'pages' => $pages,
'replies' => $row['numReplies'],
'rating' => array(
'empty' => $row['rating'] == -1,
'whole' => (int) ($row['rating'] / 2),
'half' => $row['rating'] % 2
),
'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>'
)
);

determineTopicClass($topics[$row['ID_TOPIC']]);
}
mysql_free_result($request);

if (!empty($modSettings['enableParticipation']) && !empty($topic_ids))
{
$result = db_query("
SELECT ID_TOPIC
FROM {$db_prefix}messages
WHERE ID_TOPIC IN (" . implode(', ', $topic_ids) . ")
AND ID_MEMBER = $ID_MEMBER", __FILE__, __LINE__);
while ($row = mysql_fetch_assoc($result))
{
if (empty($topics[$row['ID_TOPIC']]['is_posted_in']))
{
$topics[$row['ID_TOPIC']]['is_posted_in'] = true;
$topics[$row['ID_TOPIC']]['class'] = 'my_' . $topics[$row['ID_TOPIC']]['class'];
}
}
mysql_free_result($result);
}

}

if (!empty($topics))
    {
    echo '
        <div class="tborder" ', $context['browser']['needs_size_fix'] && !$context['browser']['is_ie6'] ? 'style="width: 100%;margin:0px;"' : 'style="margin:0px;"', '>
            <table border="0" width="100%" cellspacing="1" cellpadding="1" class="bordercolor">
                <tr>';

    echo '
                    <td class="titlebg" colspan="7">', $heading, '</td>';
    echo '
                </tr>';

    echo '
<tr class="titlebg">
<td width="2%" colspan="1"> </td>
<td>', $txt[70], '
</td><td width="14%">', $txt[109], '
</td><td width="4%" align="center">', $txt[110], '
</td><td width="4%" align="center"> Rating
</td><td width="24%">', $txt[111], '
</td>
</tr>';

foreach ($topics as $topic)
{
// Do we want to seperate the sticky and lock status out?
if (!empty($settings['seperate_sticky_lock']) && strpos($topic['class'], 'sticky') !== false)
$topic['class'] = substr($topic['class'], 0, strrpos($topic['class'], '_sticky'));
if (!empty($settings['seperate_sticky_lock']) && strpos($topic['class'], 'locked') !== false)
$topic['class'] = substr($topic['class'], 0, strrpos($topic['class'], '_locked'));

echo '
<tr>


<td class="windowbg2" valign="middle" align="center" width="4%">
<img src="' . $topic['first_post']['icon_url'] . '" alt="" align="middle" />
</td><td class="windowbg' , $topic['is_sticky'] && !empty($settings['seperate_sticky_lock']) ? '3' : '' , '" width="54%" valign="middle">' , $topic['is_locked'] && !empty($settings['seperate_sticky_lock']) ? '
<img src="' . $settings['images_url'] . '/icons/quick_lock.gif" align="right" alt="" style="margin: 0;" />' : '' , $topic['is_sticky'] && !empty($settings['seperate_sticky_lock']) ? '
<img src="' . $settings['images_url'] . '/icons/show_sticky.gif" align="right" alt="" style="margin: 0;" />' : '';
if ($topic['new'] == 0)
{
echo '<b>',  $topic['first_post']['link'], '</b>';
echo '<a href="', $topic['new_href'], '"> <img src="', $settings['images_url'], '/', $context['user']['language'], '/new.gif" alt="', $txt[302], '" /></a>';
}
else
{
echo $topic['first_post']['link'];
}
echo '
<span class="smalltext">', $topic['pages'], '<br>', $txt['smf88'], ' ', $topic['board']['link'], '</span></td>
<td class="windowbg2" valign="middle" width="14%">
', $topic['first_post']['member']['link'], '</td>
<td class="windowbg" valign="middle" width="4%" align="center">
', $topic['replies'], '</td>
<td class="windowbg" valign="middle" width="8%" align="center">';
if ($topic['rating']['empty'] == 1)
echo 'N/A';
else
{
for ($i = 0; $i < $topic['rating']['whole']; $i++)
echo '<img src="', $settings['images_url'], '/star.gif" alt="*" border="0" />';
//!!! Should have a half star!
if (!empty($topic['rating']['half']))
echo '<img src="', $settings['images_url'], '/star.gif" alt="*" border="0" />';
}
echo '
</td>
<td class="windowbg2" valign="middle" width="22%">
<a href="', $topic['last_post']['href'], '"><img src="', $settings['images_url'], '/icons/last_post.gif" alt="', $txt[111], '" title="', $txt[111], '" style="float: right;" /></a>
<span class="smalltext">
', $topic['last_post']['time'], '<br />
', $txt[525], ' ', $topic['last_post']['member']['link'], '
</span>
</td>
</tr>';
}

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

    }
else
    echo '<b><u>'.$heading.'<br><br>No Topics Match Search Criteria</u></b>';



Click on my www for example.  :up:

jacortina

OK. Finally got around to some shakedown use of this and I think it's ready for release.

Below is the function for generating Recent Topics in SMF (and other) format along with snippets for its use in blocks or an article. Additionally, the function can return the recent topics array for whatever use you might want to put it to.

As mentioned upthread and elsewhere, I've implemented this as a function in order to avoid having the same code stored over and over in the TP blocks/articles tables. If you're only going to use one instance of the code (in one article only or in one block only), you can certainly include it in the block or article. Just paste the code from the function (excluding the <? php and ?> at top/bottom) at the end of the block/article.

At the moment, the sample block and article codes are set up to load the function from the file 'JAC_Functions.php' in the forum's Sources directory. But as long as you change where it's looking, you can place it where you want. You could, if you wished, paste just the function part in your SSI.php, as others have done with custom functions (I'd rather not do this as any restore/upgrade will end up getting rid of it).

Put in a php article (no title or frame):
global $scripturl, $sourcedir, $user_info;

$func_location = $sourcedir . '/JAC_Functions.php';

if (!function_exists('JAC_RecentTopics'))
if (file_exists($func_location)) require_once($func_location);
if (!function_exists('JAC_RecentTopics')) {
echo 'Could not find the desired recent topics function.';
return;}

//////////////////////////////////////////// ---------- Use in TP PHP Article (no title or frame from theme)
//
// This will give most recent XX posted to topics -OR-
// most recent XX unreplied to topics -OR-
// topics posted to in last XX hours -OR-
// most recent XX topics on your topic notify list (Admin can specify user besides self) -OR-
// most recent XX topics on your topic bookmarks list (Admin can specify user besides self) -OR-
// most recent XX topics started by you (Admin can specify user besides self)
//
// All in the detailed topic format (Like SMF's View Unread Topics - with or without paging)*
// -OR- Minimal side block recent topics
//  -OR-    Brief, single line format
//
// Default
// index.php?page=##
// most recent posted to topics - will list
// number equal to $modSettings['defaultMaxTopics']
//
// index.php?page=##;count=50 or index.php?page=##;type=last;count=50
// 50 most recently posted to topics
//
// index.php?page=##;type=unreplied or index.php?page=##;type=unreplied;count=50
// Most recent unreplied to topics - will
// list number specified in 'count' or default to
// number equal to $modSettings['defaultMaxTopics']
//
// index.php?page=##;type=hours or index.php?page=##;type=hours;count=12
// Topics posted to in last number of hours
// specified in 'count' or default to 24.
//
// index.php?page=##;type=notify or index.php?page=##;type=notify;count=50
// Topics in topic notifcation list up to number
// specified in 'count' or a maximum of 100 topics.
//
// *** Admins Only ***
// index.php?page=##;type=notify;user=XXX or index.php?page=##;type=notify;user=XXX;count=50
// Topics in topic notifcation list of specified user up to number
// specified in 'count' or a maximum of 100 topics.
//
// index.php?page=##;type=bookmark or index.php?page=##;type=bookmark;count=50
// Topics in the bookmark list up to number
// specified in 'count' or a maximum of 100 topics.    REQUIRES Bookmark Mod
//
// *** Admins Only ***
// index.php?page=##;type=bookmark;user=XXX or index.php?page=##;type=bookmark;user=XXX;count=50
// Topics in the bookmark list of specified user up to number
// specified in 'count' or a maximum of 100 topics.    REQUIRES Bookmark Mod
//
// index.php?page=##;type=started or index.php?page=##;type=started;count=50
// Topics started by current user list up to number
// specified in 'count' or a maximum of 100 topics.
//
// *** Admins Only ***
// index.php?page=##;type=notify;user=XXX or index.php?page=##;type=started;user=XXX;count=50
// Topics started by specified user up to number
// specified in 'count' or a maximum of 100 topics.
//
// Add argument 'create' to sort by topic creation sequence (most recent first)
// rather than by last reply sequence
//
//  Add style=              fullblock - Full SMF detail format suitable for center blocks
// full      - Full SMF detail format with paging, column sort - ARTICLE ONLY
// condensed - Minimal Info Multiline Recent Topics sutable for side blocks
// line      - Minimal Info Single Line Recent Topics sutable for side/center blocks
//
// Unconditional Restrictions (only most restrictive given will be used):
//  Add excludes=#,#,#,#,#; Boards whose Topics are NOT to be listed. (least restrictive)
//  Add includes=#,#,#,#,#; Only boards whose Topics ARE to be listed.
//  Add topics=#,#,#,#,#; Only Topics which ARE to be listed. (most restrictive)
//

if ($user_info['is_guest']) {
echo 'Please <a href="', $scripturl, '?action=login"><u>Login</u></a> or <a href="', $scripturl, '?action=register"><u>Register</u></a> to view.';
}

//==========================================================================================================================

$default_type = 'last';
$default_excludes = array();
$default_style = 'fullblock';
$default_colors = 'Y';

$parm = array();

$parm['type'] = strtolower($default_type);
if (isset($_GET['type'])) $parm['type'] = strtolower($_GET['type']);

if (isset($_GET['count'])) $parm['count'] = strtolower($_GET['count']);

$select_array = 'X';
$select_array = array();
if (isset($_GET['topics'])) {
$parm['select_array'] = explode(',',$_GET['topics']);
$parm['array_type'] = 'T'; }
elseif (isset($_GET['includes'])) {
$parm['select_array'] = explode(',',$_GET['includes']);
$parm['array_type'] = 'I'; }
elseif (isset($_GET['excludes'])) {
$parm['select_array'] = explode(',',$_GET['excludes']);
$parm['array_type'] = 'X'; }
else {
$parm['select_array'] = $default_excludes;
$parm['array_type'] = 'X'; }

$parm['style'] = strtolower($default_style);
if (isset($_GET['style'])) $parm['style'] = strtolower($_GET['style']);

if (isset($_GET['create'])) $parm['sort_by_start'] = true;

if (isset($_GET['user'])) $parm['user_id'] = strtolower($_GET['user']);

if (isset($_GET['start'])) $parm['start_num'] = strtolower($_GET['start']);

if (isset($_GET['sort'])) $parm['sort_col'] = strtolower($_GET['sort']);

if (isset($_GET['asc']) || isset($_GET['ASC'])) $parm['sort_dir'] = 'asc';
if (isset($_GET['desc']) || isset($_GET['DESC'])) $parm['sort_dir'] = 'desc';

$parm['mem_colors'] = (strtoupper($default_colors) == 'Y') ? true : false;
if (isset($_GET['colors'])) $parm['mem_colors'] = true;

$parm['save_url_stub'] =  '?page='.$_GET['page'] .
                 ( isset($_GET['type']) ? ';type='.$_GET['type'] : '' ) .
                 ( isset($_GET['count']) ? ';count='.$_GET['count'] : '' ) .
                 ( isset($_GET['excludes']) ? ';excludes='.$_GET['excludes'] : '' ) .
                 ( isset($_GET['includes']) ? ';includes='.$_GET['includes'] : '' ) .
                 ( isset($_GET['topics']) ? ';topics='.$_GET['topics'] : '' ) .
                 ( isset($_GET['create']) ? ';create' : '' ) .
                 ( isset($_GET['user']) ? ';user='.$_GET['user'] : '' ) .
                 ( isset($_GET['style']) ? ';style='.$_GET['style'] : '' ) .
                 ( isset($_GET['colors']) ? ';colors' : '' );

echo '<div class="windowbg3">';
$topics = JAC_RecentTopics($parm, 'echo');
echo '</div>';

In an article, all parameters are supplied via URL query arguments. If you do an article preview, it will show using default values only. You can manually edit the URL to try out some of the available options like each of the different format styles.

I believe that this is backward compatible to earlier incarnations in that using existing URL argument lists with this new article (as long as the function file is in place) will yield compatible output EXCEPT in the matter where no 'count' parameter was specified. Previous versions used the forum's 'recent posts to show on board index' and this now uses the forum's 'topics to show per page'.


Put in a phpbox block (no title or frame):
global $settings, $user_info, $modSettings, $sourcedir;

$func_location = $sourcedir . '/JAC_Functions.php';
if (!function_exists('JAC_RecentTopics'))
if (file_exists($func_location)) require_once($func_location);
if (!function_exists('JAC_RecentTopics')) {
echo 'Could not find the desired recent topics function.';
return;}

// JAC_RecentTopics(
//
// $parm['type'] = 'last' // 'last'      - Most Recently Posted To Topics - # equal to $count argument (default)
// 'hours'     - Most Recently Posted To Topics - During laste number of hours equal to $count argument
// 'notify'    - Most Recently Posted To Topics User is Being Notified On (Watched Topics)
// 'bookmark'  - Most Recently Posted To Topics User has Bookmarked (requires Bookmark Mod)
// 'started'   - Most Recently Posted To Topics Started by User
// 'unreplied' - Most Recently Started Topics with Zero Replies.
//
// $parm['count'] = 0, // Number of Topics to show of the above types (except type=hours where it's the # of hours back to list from)
//   specify 0 (zero) to default to $modSettings['defaultMaxTopics'] (Topics to show per page), or 24
//   hours for $type='hours'
//
// $parm['array_type'] = 'X', // 'X' - Following array is of boards to exclude
// 'I' - Following array is of only boards to include
// 'T' - Following array is of only Topics to show
// $parm['select_array'] = array(),
//
// $parm['style'] = 'fullblock', //  'fullblock' - Full SMF detail format suitable for center blocks
//  'condensed' - Minimal Info Multiline Recent Topics sutable for side blocks (like TP's Recent)
//  'line'      - Minimal Info Single Line Recent Topics suitable for side/center blocks
//
// $parm['heading'] = '', // Text to put in the Table 'heading' area to label the block/box.
// leave empty to let function generate, specify 'SUPPRESS' for no heading area
//
// $parm['height'] = 0, // Height for blocks of styles 'line' and 'condensed'
// overflow: auto will casue scrollbar.
//
// $parm['mem_colors'] = true, // Output Poster names in Membergroup Colors
//
// $parm['sort_by_start'] = false, // Alter sort behavior to be by topic start date/time, ascending
//   (most useful for $type='started')


//////////////////////////////////////////// ---------- Poor Man's Global Announcements Block (center block - no Title/Frame)
// $parm['heading'] = '<center>Announcements<center>';
// $parm['array_type'] = 'T';
// $parm['select_array'] = array(1457, 2793, 2900, 2906, 2941, 3177, 3222);  // These are Topics that will be shown
////////////////////////////////////////////

//////////////////////////////////////////// ---------- Last 5 Topics Started by User Block (center block - no Title/Frame)
// $parm['heading'] = 'Most Recently Posted To Topics You Started';
// $parm['type'] = 'started';
// $parm['count'] = 5;
////////////////////////////////////////////

//////////////////////////////////////////// ---------- Boardindex Most Recent Topics Arguments
// Comment out the Info Center's Most Recent Posts Code and Insert this
// to show Most Recent Topics in full detail style instead
//
// $parm['count'] = $settings['number_recent_posts'];
// $parm['heading'] = 'Most Recently Posted To Topics';
////////////////////////////////////////////

// $parm['type'] = 'last';
// $parm['count'] = 0;
// $parm['array_type'] = 'X';
// $parm['select_array'] = array();
// $parm['style'] = 'fullblock';
// $parm['heading'] = '';
// $parm['height'] = 0;
// $parm['mem_colors'] = true;
// $parm['sort_by_start'] = false;

//-----------------------------------
$parm = array();

$parm['count'] = 10;
$parm['style'] = 'condensed';
$parm['height'] = 100;

JAC_RecentTopics($parm, 'echo');
//-----------------------------------

Defaults will be used for any and all parameters not explicitly supplied. So just supply those you need and call the function.

The 'fullblock' style won't work at all well with left or right blocks and the 'condensed' won't look right in the center. The 'line' style can work in either.


Because of post size limits, I'll attach the function file here and post it to the next message

jacortina

And, finally, the function itself:
<?php

function JAC_RecentTopics($parm = array(), $output 'echo')
{
    global 
$context$settings$scripturl$txt$db_prefix$ID_MEMBER$user_info$modSettings$user_profile$options;
    
$do_query 1;

    
$valid_recent_types = array('last''unreplied''hours''notify''bookmark''started');
    
$valid_array_types = array('X''I''T');
    
$valid_out_styles = array('fullblock''full''condensed''line'); 
    
$valid_sorts = array('last_post''subject''starter''replies''views''first_post');
    
$sort_dirs = array(
        
'last_post' => array('DESC''asc'),
        
'subject' => array('ASC''desc'),
        
'starter' => array('ASC''desc'),
        
'replies' => array('ASC''desc'),
        
'views' => array('ASC''desc'),
        
'first_post' => array('ASC''desc'),
    );

    
$output strtolower($output) != 'array' 'echo' 'array';

    if (!
is_array($parm)) {
        if (
$output 'array') {
            return array();}
        else {
            echo 
'Unexpected argument - expecting parameter array)';
            return; }
    }

if(!empty($options['num_topics_page']))
$modSettings['defaultMaxTopics'] = $options['num_topics_page'];
if(!empty($options['num_posts_page']))
$modSettings['defaultMaxMessages'] = $options['num_posts_page'];

    
$parm['type'] = (isset($parm['type']) && !empty($parm['type']) && in_array(strtolower($parm['type']), $valid_recent_types)) ? strtolower($parm['type']) : $valid_recent_types[0];

    
$parm['count'] = (isset($parm['count']) && !empty($parm['count']) && is_numeric($parm['count'])) ? $parm['count'] : 0;

    
$parm['array_type'] = (isset($parm['array_type']) && !empty($parm['array_type']) && in_array(strtoupper($parm['array_type']), $valid_array_types)) ? strtoupper($parm['array_type']) : $valid_array_types[0];

    
$parm['select_array'] = (isset($parm['select_array']) && !empty($parm['select_array']) && is_array($parm['select_array'])) ? $parm['select_array'] : array();

    
$parm['style'] = (isset($parm['style']) && !empty($parm['style']) && in_array(strtolower($parm['style']), $valid_out_styles)) ? strtolower($parm['style']) : $valid_out_styles[0];

    
$parm['heading'] = (isset($parm['heading'])) ? $parm['heading'] : '';

    
$parm['sort_by_start'] = (isset($parm['sort_by_start']) && ($parm['sort_by_start'] === true)) ? true false;

    
$parm['user_id'] = (isset($parm['user_id']) && !empty($parm['user_id']) && is_numeric($parm['user_id'])) ? $parm['user_id'] : 0;
    
$parm['user_id'] = $parm['user_id'] != $parm['user_id'] : $ID_MEMBER;

    
$parm['start_num'] = (isset($parm['start_num']) && !empty($parm['start_num']) && is_numeric($parm['start_num'])) ? $parm['start_num'] : 0;

    
$parm['sort_col'] = (isset($parm['sort_col']) && !empty($parm['sort_col']) && in_array(strtolower($parm['sort_col']), $valid_sorts)) ? strtolower($parm['sort_col']) : $valid_sorts[0];

    
$parm['sort_dir'] = (isset($parm['sort_dir']) && ((strtoupper($parm['sort_dir']) == 'ASC') || (strtoupper($parm['sort_dir']) == 'DESC'))) ? strtoupper($parm['sort_dir']) : '';
    
$cur_dir $parm['sort_dir'] != '' $parm['sort_dir'] : $sort_dirs[$parm['sort_col']];

    
$parm['save_url_stub'] = (isset($parm['save_url_stub'])) ? $parm['save_url_stub'] : '';

    
$parm['mem_colors'] = (isset($parm['mem_colors']) && ($parm['mem_colors'] === false)) ? false true;

    
$parm['height'] = (isset($parm['height'])) ? $parm['height'] : 0;

    
$parm['per_page'] = (isset($parm['per_page']) && !empty($parm['per_page']) && is_numeric($parm['per_page'])) ? $parm['per_page'] : 0;
    
$parm['per_page'] = $parm['per_page'] > $parm['per_page'] : $modSettings['defaultMaxTopics'];

    
$constraint '';
    if (
$parm['type'] == 'bookmark')
if( mysql_num_rowsmysql_query("SHOW TABLES LIKE '"$db_prefix"bookmarks'") ) == )
            
$parm['type'] == 'notify';

    if ((
$parm['type'] == 'bookmark') || ($parm['type'] == 'notify')) {
    
$watched_topics = array();
        if (
$parm['type'] == 'bookmark')
        
$request db_query("SELECT ID_TOPIC FROM {$db_prefix}bookmarks WHERE ID_MEMBER = {$parm['user_id']}"__FILE____LINE__);
        if (
$parm['type'] == 'notify')
        
$request db_query("SELECT ID_TOPIC FROM {$db_prefix}log_notify WHERE ID_MEMBER = {$parm['user_id']} AND ID_BOARD = 0"__FILE____LINE__);
    
while ($row mysql_fetch_assoc($request))
            
$watched_topics[] = $row['ID_TOPIC'];
mysql_free_result($request);
if (count($watched_topics) == 0)
$do_query 0;
    
else
    
$constraint =' t.ID_TOPIC IN (' implode(', '$watched_topics) . ')';
    }

    
$type_methods = array(
        
'last' =>   ($parm['array_type'] == 'X' ? (($parm['count'] != 0) ? ('t.ID_LAST_MSG >= ' . ($modSettings['maxMsgID'] - (150 max($parm['count'], $parm['per_page'])))) : '1' ) : '1'),
        
'unreplied' => 't.numReplies = 0',
        
'hours' => $parm['count'] == 'ml.posterTime >= ' strtotime('1 day ago') : 'ml.posterTime >= ' strtotime($parm['count'] . ' hours ago'),
        
'notify' => $constraint,
        
'bookmark' => $constraint,
        
'started' => 't.ID_MEMBER_STARTED = ' $parm['user_id'],
    );
    
$type_method_clause $type_methods[$parm['type']];

    
$select_methods = array(
        
'X' => count($parm['select_array']) == '' ' AND b.ID_BOARD NOT IN (' implode(', '$parm['select_array']) . ')',
        
'I' => count($parm['select_array']) == '' ' AND b.ID_BOARD IN (' implode(', '$parm['select_array']) . ')',
        
'T' => count($parm['select_array']) == '' ' AND t.ID_TOPIC IN (' implode(', '$parm['select_array']) . ')',
    );
    
$select_method_clause $select_methods[$parm['array_type']];

    
$sort_methods = array(
    
'last_post' => ($parm['sort_by_start'] ? 't.ID_FIRST_MSG' 't.ID_LAST_MSG'),
    
'subject' => 'ms.subject',
    
'starter' => 'IFNULL(mems.realName, ms.posterName)',
    
'replies' => 't.numReplies',
    
'views' => 't.numViews',
    
'first_post' => 't.ID_TOPIC',
    );
    
$sort_method_clause ' ORDER BY '$sort_methods[$parm['sort_col']] . ' ' . ($parm['sort_dir'] == '' $sort_dirs[$parm['sort_col']][0] : $parm['sort_dir']);

    
$type_heading = array(
   
    'last' => 'Most Recently Posted To Topics',
       
'unreplied' => 'Unreplied To Topics',
        
'hours' => 'Topics Posted To In Last '. ($parm['count'] == 24 $parm['count']) . ' Hours',
        
'notify' => 'Topics Being Watched' . ($ID_MEMBER == $parm['user_id'] ? '' : (' by User# ' $parm['user_id'])),
        
'bookmark' => 'Topics Bookmarked' . ($ID_MEMBER == $parm['user_id'] ? '' : (' by User# ' $parm['user_id'])),
        
'started' => 'Topics Started ' . ($ID_MEMBER == $parm['user_id'] ? ' by You' : (' by User# ' $parm['user_id'])),
    );

$limit_clause $parm['type'] == 'hours' '' : ($parm['count'] == ' LIMIT '.$modSettings['defaultMaxTopics'] : ' LIMIT '.$parm['count']);

$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';

$topics = array();

if ($do_query == 1)
{
$groupcolors = array();
        if (
$parm['mem_colors']) {
    
$request db_query("SELECT ID_GROUP, onlineColor FROM {$db_prefix}membergroups"__FILE____LINE__);
     while ($row mysql_fetch_assoc($request))
     $groupcolors[$row['ID_GROUP']] = $row['onlineColor'];
    
mysql_free_result($request);
    
}

        if (
$parm['style'] == 'full') {
$request db_query("
SELECT b.ID_BOARD
FROM 
{$db_prefix}boards AS b
WHERE " 
$user_info['query_see_board'] . (!empty($modSettings['recycle_enable']) && ($modSettings['recycle_board'] > 0) ? "
AND b.ID_BOARD != " 
. (int) $modSettings['recycle_board'] : '') .
$select_method_clause,
__FILE____LINE__);
    
$boards = array();
    
while ($row mysql_fetch_assoc($request))
    
$boards[] = $row['ID_BOARD'];
    
mysql_free_result($request);
    
$query_this_board = empty($boards) ? '' 'WHERE t.ID_BOARD IN (' implode(', '$boards) . ')';

    $request db_query("
    SELECT COUNT(*), MIN(t.ID_LAST_MSG)
       FROM 
{$db_prefix}topics AS t, {$db_prefix}messages AS ml " .
$query_this_board "
AND ml.ID_MSG = t.ID_LAST_MSG " 
.
$select_method_clause "
AND " 
$type_method_clause,
__FILE____LINE__);
    
list ($num_topics$min_message) = mysql_fetch_row($request);
    
mysql_free_result($request);
            
$limit_clause 'LIMIT ' $parm['start_num'] . ', ' $parm['per_page'];
        }

$query "
SELECT
ms.subject AS firstSubject, ms.posterTime AS firstPosterTime, ms.ID_TOPIC, t.ID_BOARD, b.name AS bname,
t.numReplies, t.numViews, ms.ID_MEMBER AS ID_FIRST_MEMBER, ml.ID_MEMBER AS ID_LAST_MEMBER,
ml.posterTime AS lastPosterTime, IFNULL(mems.realName, ms.posterName) AS firstPosterName,
IFNULL(meml.realName, ml.posterName) AS lastPosterName,
mems.ID_GROUP as mems_group, meml.ID_GROUP as meml_group, mems.ID_POST_GROUP as mems_pgroup,
ml.subject AS lastSubject, b.memberGroups, meml.ID_POST_GROUP as meml_pgroup,
ml.icon AS lastIcon, ms.icon AS firstIcon, t.ID_POLL, t.isSticky, t.locked, ml.modifiedTime AS lastModifiedTime,
ml.body AS lastBody, ms.body AS firstBody,
ml.smileysEnabled AS lastSmileys, ms.smileysEnabled AS firstSmileys, t.ID_FIRST_MSG, t.ID_LAST_MSG,"
. ($user_info['is_guest'] ? '1 AS isRead, 0 AS new_from' '
IFNULL(lt.ID_MSG, IFNULL(lmr.ID_MSG, 0)) >= ml.ID_MSG_MODIFIED AS isRead,
IFNULL(lt.ID_MSG, IFNULL(lmr.ID_MSG, -1)) + 1 AS new_from'
) . "
FROM (
{$db_prefix}messages AS ms, {$db_prefix}messages AS ml, {$db_prefix}topics AS t, {$db_prefix}boards AS b)
LEFT JOIN 
{$db_prefix}members AS mems ON (mems.ID_MEMBER = ms.ID_MEMBER)
LEFT JOIN 
{$db_prefix}members AS meml ON (meml.ID_MEMBER = ml.ID_MEMBER)
LEFT JOIN 
{$db_prefix}log_topics AS lt ON (lt.ID_TOPIC = t.ID_TOPIC AND lt.ID_MEMBER = $ID_MEMBER)
LEFT JOIN 
{$db_prefix}log_mark_read AS lmr ON (lmr.ID_BOARD = t.ID_BOARD AND lmr.ID_MEMBER = $ID_MEMBER)
WHERE " 
$type_method_clause " " .
    $select_method_clause " " .
   "AND t.ID_TOPIC = ms.ID_TOPIC
AND b.ID_BOARD = t.ID_BOARD " 
.
(!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > " AND b.ID_BOARD != $modSettings[recycle_board]'') .
   " AND ms.ID_MSG = t.ID_FIRST_MSG
AND ml.ID_MSG = t.ID_LAST_MSG
AND " 
$user_info['query_see_board'] . " " .
$sort_method_clause " " $limit_clause;

$request db_query($query__FILE____LINE__);

$topic_ids = array();
while ($row mysql_fetch_assoc($request))
{
if ($row['ID_POLL'] > && $modSettings['pollMode'] == '0')
continue;

$topic_ids[] = $row['ID_TOPIC'];

// Clip the strings first because censoring is slow :/. (for some reason?)
$row['firstBody'] = strip_tags(strtr(parse_bbc($row['firstBody'], $row['firstSmileys'], $row['ID_FIRST_MSG']), array('<br />' => '')));

if ($row['ID_FIRST_MSG'] == $row['ID_LAST_MSG'])
{
$row['lastSubject'] = $row['firstSubject'];
$row['lastBody'] = $row['firstBody'];
}
        else
        {
    $row['lastBody'] = strip_tags(strtr(parse_bbc($row['lastBody'], $row['lastSmileys'], $row['ID_LAST_MSG']), array('<br />' => '')));
        }

// Decide how many pages the topic should have.
$topic_length $row['numReplies'] + 1;
if ($topic_length $modSettings['defaultMaxMessages'])
{
$tmppages = array();
$tmpa 1;
for ($tmpb 0$tmpb $topic_length$tmpb += $modSettings['defaultMaxMessages'])
{
$tmppages[] = '<a href="' $scripturl '?topic=' $row['ID_TOPIC'] . '.' $tmpb ';topicseen">' $tmpa '</a>';
$tmpa++;
}

// Show links to all the pages?
if (count($tmppages) <= 5)
$pages '« ' implode(' '$tmppages);
// Or skip a few?
else
$pages '« ' $tmppages[0] . ' ' $tmppages[1] . ' ... ' $tmppages[count($tmppages) - 2] . ' ' $tmppages[count($tmppages) - 1];

if (!empty($modSettings['enableAllMessages']) && $topic_length $modSettings['enableAllMessages'])
$pages .= '  <a href="' $scripturl '?topic=' $row['ID_TOPIC'] . '.0;all">' $txt[190] . '</a>';
$pages .= ' Â»';
}
else
$pages '';

// We need to check the topic icons exist... you can never be too sure!
if (empty($modSettings['messageIconChecks_disable']))
{
// First icon first... as you'd expect.
if (!isset($icon_sources[$row['firstIcon']]))
$icon_sources[$row['firstIcon']] = file_exists($settings['theme_dir'] . '/images/post/' $row['firstIcon'] . '.gif') ? 'images_url' 'default_images_url';
// Last icon... last... duh.
if (!isset($icon_sources[$row['lastIcon']]))
$icon_sources[$row['lastIcon']] = file_exists($settings['theme_dir'] . '/images/post/' $row['lastIcon'] . '.gif') ? 'images_url' 'default_images_url';
}

// And build the array.
$topics[$row['ID_TOPIC']] = array(
'id' => $row['ID_TOPIC'],
'first_post' => array(
'id' => $row['ID_FIRST_MSG'],
'member' => array(
'name' => $row['firstPosterName'],
'id' => $row['ID_FIRST_MEMBER'],
'href' => $scripturl '?action=profile;u=' $row['ID_FIRST_MEMBER'],
'link' => !empty($row['ID_FIRST_MEMBER']) ? ('<a href="' $scripturl '?action=profile;u=' $row['ID_FIRST_MEMBER'] . '" title="' $txt[92] . ' ' $row['firstPosterName'] . '">' . ( $parm['mem_colors'] ? ( !empty($groupcolors[$row['mems_group']]) || !empty($groupcolors[$row['mems_pgroup']])  ? '<font color="'. ( !empty($groupcolors[$row['mems_group']]) ? $groupcolors[$row['mems_group']] : $groupcolors[$row['mems_pgroup']] ) . '">' '' ) : '' )  . $row['firstPosterName'] . (( $parm['mem_colors'] && ( !empty($groupcolors[$row['mems_group']]) || !empty($groupcolors[$row['mems_pgroup']]))) ? '</font>' '' ) . '</a>' ) : $row['firstPosterName']
),
'time' => timeformat($row['firstPosterTime']),
'timestamp' => forum_time(true$row['firstPosterTime']),
'subject' => $row['firstSubject'],
'short_subject' => shorten_subject($row['firstSubject'], 25),
'preview' => shorten_subject($row['firstBody'],128),
'body' => $row['firstBody'],
'icon' => $row['firstIcon'],
'icon_url' => $settings[$icon_sources[$row['firstIcon']]] . '/post/' $row['firstIcon'] . '.gif',
'href' => $scripturl '?topic=' $row['ID_TOPIC'] . '.0;topicseen',
'link' => '<a href="' $scripturl '?topic=' $row['ID_TOPIC'] . '.0;topicseen">' $row['firstSubject'] . '</a>'
),
'last_post' => array(
'id' => $row['ID_LAST_MSG'],
'member' => array(
'name' => $row['lastPosterName'],
'id' => $row['ID_LAST_MEMBER'],
'href' => $scripturl '?action=profile;u=' $row['ID_LAST_MEMBER'],
'link' => !empty($row['ID_LAST_MEMBER']) ? '<a href="' $scripturl '?action=profile;u=' $row['ID_LAST_MEMBER'] . '" title="' $txt[92] . ' ' $row['lastPosterName'] . '">' . ( $parm['mem_colors'] ? ( !empty($groupcolors[$row['meml_group']]) || !empty($groupcolors[$row['meml_pgroup']]) ? '<font color="'. ( !empty($groupcolors[$row['meml_group']]) ? $groupcolors[$row['meml_group']] : $groupcolors[$row['meml_pgroup']] ) .'">' '' ) : '' ) . $row['lastPosterName'] . (( $parm['mem_colors'] && ( !empty($groupcolors[$row['meml_group']]) || !empty($groupcolors[$row['meml_pgroup']]))) ? '</font>' '' ) . '</a>' $row['lastPosterName']
),
'time' => timeformat($row['lastPosterTime']),
'timestamp' => forum_time(true$row['lastPosterTime']),
'subject' => $row['lastSubject'],
'short_subject' => shorten_subject($row['lastSubject'], 25),
'preview' => shorten_subject($row['lastBody'],128),
'body' => $row['lastBody'],
'icon' => $row['lastIcon'],
'icon_url' => $settings[$icon_sources[$row['lastIcon']]] . '/post/' $row['lastIcon'] . '.gif',
'href' => $scripturl '?topic=' $row['ID_TOPIC'] . ($row['numReplies'] == '.0' '.msg' $row['ID_LAST_MSG']) . ';topicseen#msg' $row['ID_LAST_MSG'],
'link' => '<a href="' $scripturl '?topic=' $row['ID_TOPIC'] . ($row['numReplies'] == '.0' '.msg' $row['ID_LAST_MSG']) . ';topicseen#msg' $row['ID_LAST_MSG'] . '">' $row['lastSubject'] . '</a>'
),
'new' => !$row['isRead'],
'new_from' => $row['new_from'],
'new_href' => $scripturl '?topic=' $row['ID_TOPIC'] . '.msg' $row['new_from'] . ';topicseen#new',
'href' => $scripturl '?topic=' $row['ID_TOPIC'] . ($row['numReplies'] == '.0' '.msg' $row['new_from']) . ';topicseen' . ($row['numReplies'] == '' 'new'),
'link' => '<a href="' $scripturl '?topic=' $row['ID_TOPIC'] . ($row['numReplies'] == '.0' '.msg' $row['new_from']) . ';topicseen#msg' $row['new_from'] . '">' $row['firstSubject'] . '</a>',
'is_sticky' => !empty($modSettings['enableStickyTopics']) && !empty($row['isSticky']),
'is_locked' => !empty($row['locked']),
'is_poll' => $modSettings['pollMode'] == '1' && $row['ID_POLL'] > 0,
'is_hot' => $row['numReplies'] >= $modSettings['hotTopicPosts'],
'is_very_hot' => $row['numReplies'] >= $modSettings['hotTopicVeryPosts'],
'is_posted_in' => false,
'icon' => $row['firstIcon'],
'icon_url' => $settings[$icon_sources[$row['firstIcon']]] . '/post/' $row['firstIcon'] . '.gif',
'subject' => $row['firstSubject'],
'pages' => $pages,
'replies' => $row['numReplies'],
'views' => $row['numViews'],
'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>'
)
);

determineTopicClass($topics[$row['ID_TOPIC']]);
}
mysql_free_result($request);

if (!empty($modSettings['enableParticipation']) && !empty($topic_ids))
{
$result db_query("
SELECT ID_TOPIC
FROM 
{$db_prefix}messages
WHERE ID_TOPIC IN (" 
implode(', '$topic_ids) . ")
AND ID_MEMBER = 
$ID_MEMBER"__FILE____LINE__);
while ($row mysql_fetch_assoc($result))
{
if (empty($topics[$row['ID_TOPIC']]['is_posted_in']))
{
$topics[$row['ID_TOPIC']]['is_posted_in'] = true;
$topics[$row['ID_TOPIC']]['class'] = 'my_' $topics[$row['ID_TOPIC']]['class'];
}
}
mysql_free_result($result);
}

}

if ($output == 'array')
    return $topics;

if ( ($parm['style'] == 'full') || ($parm['style'] == 'fullblock') )
{
if (!empty($topics))
    {

    if ($parm['style'] == 'full') {
        $page_url $parm['save_url_stub'] . ';sort=' $parm['sort_col'] . ( ($parm['sort_dir'] != '') ? ';'.$parm['sort_dir'] : '');
        $current_page = (int) $parm['start_num'] / $parm['per_page'];
        $links = array(
            'first' => $parm['start_num'] >= $parm['per_page'] ? $scripturl $page_url ';start=0' '',
            'prev' => $parm['start_num'] >= $parm['per_page'] ? $scripturl .  $page_url ';start=' . ($parm['start_num'] - $parm['per_page']) : '',
            'next' => $parm['start_num'] + $parm['per_page'] < $num_topics $scripturl .  $page_url ';start=' . ($parm['start_num'] + $parm['per_page']) : '',
            'last' =>  ( ($parm['start_num'] + $parm['per_page']) < $num_topics) ? ($scripturl .  $page_url ';start=' . (floor(($num_topics 1) / $parm['per_page']) * $parm['per_page']) ) : '',
            'up' => $scripturl,
        );
        
$page_info = array(
            'current_page' => floor($parm['start_num'] / $parm['per_page']) + 1,
        
    'num_pages' => floor(($num_topics 1) / $parm['per_page']) + 1,
                    
'page_index' => constructPageIndex($scripturl $parm['save_url_stub'] . ';sort=' $parm['sort_col'] . ( ($parm['sort_dir'] != '') ? ';'.$parm['sort_dir'] : ''), $parm['start_num'], $num_topics$parm['per_page'], false),
        );

            
echo '
                 <table border="0" width="100%" cellpadding="0" cellspacing="0">
                  <tr>
                  <td class="middletext" valign="middle">' 
$txt[139] . ': ' $page_info['page_index'] . '</td>
                 </tr>
                 </table>'
;
    }

    echo '
        <div class="tborder" '
$context['browser']['needs_size_fix'] && !$context['browser']['is_ie6'] ? 'style="width: 100%;margin:0px;"' 'style="margin:0px;"''>
            <table border="0" width="100%" cellspacing="1" cellpadding="1" class="bordercolor">'
;


if ($parm['heading'] != 'SUPPRESS') {
    
echo '
<tr>'
;
echo '
<td class="titlebg" colspan="7">'
, ($parm['heading'] == '' $type_heading[$parm['type']] : $parm['heading']), '</td>';
echo '
</tr>'
;
}

    if ($parm['style'] == 'fullblock') {
        echo '
<tr class="titlebg">
<td width="10%" colspan="2"> </td>
<td>'
$txt[70], '
</td><td width="14%">'
$txt[109], '
</td><td width="4%" align="center">'
$txt[110], '
</td><td width="4%" align="center">'
$txt[301], '
</td><td width="24%">'
$txt[111], '
</td>
</tr>'
;
    }

    if ($parm['style'] == 'full') {
        echo '
<tr class="titlebg">
<td width="10%" colspan="2"> </td>
<td>
<a href="'
$parm['save_url_stub'], ';sort=subject', ($parm['sort_col'] != 'subject' '' : ($parm['sort_dir'] == '' ';order='.$sort_dirs[$parm['sort_col']][1] : '')), '">'$txt[70], (($parm['sort_col'] != 'subject') ? '' : (' <img src="' $settings['images_url'] . '/sort_' . (($cur_dir == 'DESC') ? 'down' 'up') . '.gif" alt="" border="0" />')), '</a>
</td><td width="14%">
    <a href="'
$parm['save_url_stub'], ';sort=starter', ($parm['sort_col'] != 'starter' '' : ($parm['sort_dir'] == '' ';order='.$sort_dirs[$parm['sort_col']][1] : '')), '">'$txt[70], (($parm['sort_col'] != 'starter') ? '' : (' <img src="' $settings['images_url'] . '/sort_' . (($cur_dir == 'DESC') ? 'down' 'up') . '.gif" alt="" border="0" />')), '</a>
</td><td width="4%" align="center">
    <a href="'
$parm['save_url_stub'], ';sort=replies', ($parm['sort_col'] != 'replies' '' : ($parm['sort_dir'] == '' ';order='.$sort_dirs[$parm['sort_col']][1] : '')), '">'$txt[70], (($parm['sort_col'] != 'replies') ? '' : (' <img src="' $settings['images_url'] . '/sort_' . (($cur_dir == 'DESC') ? 'down' 'up') . '.gif" alt="" border="0" />')), '</a>
</td><td width="4%" align="center">
    <a href="'
$parm['save_url_stub'], ';sort=views', ($parm['sort_col'] != 'views' '' : ($parm['sort_dir'] == '' ';order='.$sort_dirs[$parm['sort_col']][1] : '')), '">'$txt[70], (($parm['sort_col'] != 'views') ? '' : (' <img src="' $settings['images_url'] . '/sort_' . (($cur_dir == 'DESC') ? 'down' 'up') . '.gif" alt="" border="0" />')), '</a>
</td><td width="24%">
    <a href="'
$parm['save_url_stub'], ';sort=last_post', ($parm['sort_col'] != 'last_post' '' : ($parm['sort_dir'] == '' ';order='.$sort_dirs[$parm['sort_col']][1] : '')), '">'$txt[70], (($parm['sort_col'] != 'last_post') ? '' : (' <img src="' $settings['images_url'] . '/sort_' . (($cur_dir == 'DESC') ? 'down' 'up') . '.gif" alt="" border="0" />')), '</a>
</td>
</tr>'
;
    }

foreach ($topics as $topic)
{
// Do we want to seperate the sticky and lock status out?
if (!empty($settings['seperate_sticky_lock']) && strpos($topic['class'], 'sticky') !== false)
$topic['class'] = substr($topic['class'], 0strrpos($topic['class'], '_sticky'));
if (!empty($settings['seperate_sticky_lock']) && strpos($topic['class'], 'locked') !== false)
$topic['class'] = substr($topic['class'], 0strrpos($topic['class'], '_locked'));

echo '
<tr>
<td class="windowbg2" valign="middle" align="center" width="6%">
<img src="' 
$settings['images_url'] . '/topic/' $topic['class'] . '.gif" alt="" />
</td><td class="windowbg2" valign="middle" align="center" width="4%">
<img src="' 
$topic['first_post']['icon_url'] . '" alt="" align="middle" />
</td><td class="windowbg' 
$topic['is_sticky'] && !empty($settings['seperate_sticky_lock']) ? '3' '' '" width="48%" valign="middle">' $topic['is_locked'] && !empty($settings['seperate_sticky_lock']) ? '
<img src="' 
$settings['images_url'] . '/icons/quick_lock.gif" align="right" alt="" style="margin: 0;" />' '' $topic['is_sticky'] && !empty($settings['seperate_sticky_lock']) ? '
<img src="' 
$settings['images_url'] . '/icons/show_sticky.gif" align="right" alt="" style="margin: 0;" />' '';
if ($topic['new'])
{
echo '<b>',  $topic['first_post']['link'], '</b>';
echo '<a href="'$topic['new_href'], '"> <img src="'$settings['images_url'], '/'$context['user']['language'], '/new.gif" alt="'$txt[302], '" /></a>';
}
else
{
echo $topic['first_post']['link'];
}
  echo '
<span class="smalltext">'
$topic['pages'], '<br>'$txt['smf88'], ' '$topic['board']['link'], '</span></td>
<td class="windowbg2" valign="middle" width="14%">
'
$topic['first_post']['member']['link'], '</td>
<td class="windowbg" valign="middle" width="4%" align="center">
'
$topic['replies'], '</td>
<td class="windowbg" valign="middle" width="4%" align="center">
'
$topic['views'], '</td>
<td class="windowbg2" valign="middle" width="22%">
<a href="'
$topic['last_post']['href'], '"><img src="'$settings['images_url'], '/icons/last_post.gif" alt="'$txt[111], '" title="'$txt[111], '" style="float: right;" /></a>
<span class="smalltext">
'
$topic['last_post']['time'], '<br />
'
$txt[525], ' '$topic['last_post']['member']['link'], '
</span>
</td>
</tr>'
;
}

    echo '</table>';

    echo '</div>';

    if ($parm['style'] == 'full') {

            
echo '
                 <table border="0" width="100%" cellpadding="0" cellspacing="0">
                  <tr>
                  <td class="middletext" valign="middle">' 
$txt[139] . ': ' $page_info['page_index'] . '</td>
                 </tr>
                 </table>'
;

    echo'
<div class="tborder"><div class="titlebg2">
<table cellpadding="8" cellspacing="0" width="55%">
<tr>
<td align="left" style="padding-top: 2ex;" class="smalltext">'
, !empty($modSettings['enableParticipation']) ? '
<img src="' 
$settings['images_url'] . '/topic/my_normal_post.gif" alt="" align="middle" /> ' $txt['participation_caption'] . '<br />' '''
<img src="' 
$settings['images_url'] . '/topic/normal_post.gif" alt="" align="middle" /> ' $txt[457] . '<br />
<img src="' 
$settings['images_url'] . '/topic/hot_post.gif" alt="" align="middle" /> ' $txt[454] . '<br />
<img src="' 
$settings['images_url'] . '/topic/veryhot_post.gif" alt="" align="middle" /> ' $txt[455] . '
</td>
<td align="left" valign="top" style="padding-top: 2ex;" class="smalltext">
<img src="' 
$settings['images_url'] . '/icons/quick_lock.gif" alt="" align="middle" /> ' $txt[456] . '<br />' . ($modSettings['enableStickyTopics'] == '1' '
<img src="' 
$settings['images_url'] . '/icons/' . (!empty($settings['seperate_sticky_lock']) ? 'quick_sticky' 'normal_post_sticky') . '.gif" alt="" align="middle" /> ' $txt['smf96'] . '<br />' '') . ($modSettings['pollMode'] == '1' '
<img src="' 
$settings['images_url'] . '/topic/normal_poll.gif" alt="" align="middle" /> ' $txt['smf43'] : '') . '
</td>
</tr>
</table>
</div>'
;
    }

    }
else
    

    
echo '<b><u>',($parm['heading'] == '' $type_heading[$parm['type']] : $parm['heading']),'<br><br>No Topics Match Search Criteria</u></b>';
    }
}

if ($parm['style'] == 'condensed')
{
$counter=1$cmax=count($topics);
$height_clause = (isset($parm['height']) && ($parm['height'] > 0) ? ' height: '.$parm['height'].'px;' '');
echo ' <div style="width: 100%;'$height_clause' overflow: auto;">
<div class="windowbg" style="width: 100%; overflow: hidden;">'
;
foreach ($topics as $w)
{
echo '
<div class="smalltext"><a href="'
.$w['last_post']['href'].'">'. ($w['new'] ? '<b>' '') . $w['last_post']['short_subject'] . ($w['new'] ? '</b>' '') .'</a></div>
<div class="smalltext">'
$txt[525], ' <b>'$w['last_post']['member']['link'], '</b> ';
if($w['new'])
echo '<a href="'.$w['new_href'].'"><img border="0" src="'.$settings['images_url'].'/'.$context['user']['language'].'/new.gif" alt="new" /></a> ';

echo '</div><div class="smalltext">';
echo '['.$w['last_post']['time'].']
</div>'
;

if($counter != $cmax)
echo '<hr />';
$counter++;
}
echo '
</div></div>'
;
}

if ($parm['style'] == 'line')
{
$counter=1$cmax=count($topics);
$height_clause = (isset($parm['height']) && ($parm['height'] > 0) ? ' height: '.$parm['height'].'px;' '');
echo ' <div style="width: 100%;'$height_clause' overflow: auto;">
<div class="windowbg" style="width: 100%; overflow: hidden;">'
;
foreach ($topics as $w)
{
echo '<div class="windowbg'. ((($counter 2) == 0) ? '' '2') . '" style="width: 100%;line-height: 1.4em">';
echo '
<span class="smalltext"><a href="'
.$w['last_post']['href'].'">'. ($w['new'] ? '<b>' '') . $w['last_post']['subject'] . ($w['new'] ? '</b>' '') .'</a>  </span>
<span class="smalltext">(in '
.$w['board']['link'].')  </span>
<span class="smalltext">'
$txt[525], ' <b>'$w['last_post']['member']['link'], '</b>  </span>
<span class="smalltext">'
;
if($w['new'])
echo '<a href="'.$w['new_href'].'"><img border="0" src="'.$settings['images_url'].'/'.$context['user']['language'].'/new.gif" alt="new" /></a> ';

echo '['.$w['last_post']['time'].']
</span><br />'
;

$counter++;
echo '
</div>'
;
}
echo '
</div></div>'
;
}

}

?>

dannbass

Wow! Thank you very much! I'm speechless!
It is just what I needed, again thank you for all the work!

gffb

#378
I have been looking through this topic and it nearly does what I would like the only thing I cant seem to find is how to make a block just show unread topics ie NEW like this index.php?action=unread

G6Cad

More or less the built in recent topics block do just that.