SimplePortal

Customization => Blocks and Modifications => Topic started by: Blue on March 03, 2009, 06:53:46 PM

Title: A Better Recent Topics
Post by: Blue on March 03, 2009, 06:53:46 PM
[FOR SMF 2.0 ONLY]

Hi,

I wanted to exclude some boards from the normal recent topics. I didn't know how then I tried to understand how php for smf works. Well... I understood and I did some modifications to recent topics. Here is a demo:
(http://chromesociety.com/Downloads/test.png)

1- Img of your choice
2- Subject from the topic
3- How many people saw?
4- Last Member who posted
5- How many people comment?
6- Category
7- Title of your choice
8- If you have the mod "Thank-o-matic" it says how many thank you was given to the topic

To change point 1 find (and replace YOUR URL):
Code: [Select]
<td valign="middle"><img src="YOUR URL" border="0" /></td>
To change point 7 find (and replace YOUR TEXT):
Code: [Select]
<td valign="middle" width="100%" style="padding: 5px;"> YOUR TEXT
If you want to translate the mod to your language find (and replace posted by, in, visits and comments to your language):
Code: [Select]
<div style="font-size: 9px;">Posted by ', $post['poster']['link'], ' in ', $post['board']['link'], ' | ', $post['time'], '
<div style="font-size: 9px;">
<i>(Visits: ', $post['views'], ' | Comments: ', $post['replies'], ')</i></font>

If you want to limit the block to some boards find:
Code: [Select]
$exclude_boards = null;
and replace to:
Code: [Select]
$exclude_boards = array(IDBLOCK1, IDBLOCK2);where IDBLOCK1 and IDBLOCK2 are your board's ID that you want to exclude.

If you want to limit your block to show only X topics find:
Code: [Select]
$num_recent = !empty($parameters[0]) ? $parameters[0] :  (isset($_GET['limit']) ? (int) $_GET['limit'] : 5);
and replace 5 to the number that you want

Finally,
Here is the code (without mod for Thank-o-matic)
Code: [Select]
global $context, $settings, $scripturl, $txt;
global $user_info, $modSettings, $smcFunc, $posts;
global $color_profile;

$exclude_boards = null;
$num_recent = !empty($parameters[0]) ? $parameters[0] :  (isset($_GET['limit']) ? (int) $_GET['limit'] : 5);

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

// Find all the posts in distinct topics.  Newer ones will have higher IDs.
$request = $smcFunc['db_query']('','
SELECT
m.poster_time, ms.subject, m.id_topic, m.id_member, m.id_msg, b.id_board, t.num_replies, t.num_views, b.name AS bName,
IFNULL(mem.real_name, m.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)) >= m.id_msg_modified AS is_read,
IFNULL(lt.id_msg, IFNULL(lmr.ID_MSG, -1)) + 1 AS new_from') . ', LEFT(m.body, 384) AS body, m.smileys_enabled, m.icon
FROM ({db_prefix}messages AS m, {db_prefix}topics AS t, {db_prefix}boards AS b, {db_prefix}messages AS ms)
LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.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:id_member})
LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = b.id_board AND lmr.id_member = {int:id_member})' : '') . '
WHERE t.ID_LAST_MSG >= ' . ($modSettings['maxMsgID'] - 35 * min($num_recent, 5)) . '
AND t.id_last_msg = m.id_msg
AND b.id_board = t.id_board' . (empty($exclude_boards) ? '' : '
AND b.id_board NOT IN ({array_int:exclude_boards})'). '
AND {raw:query_see_board}
AND ms.id_msg = t.id_last_msg
ORDER BY t.id_last_msg DESC
LIMIT {int:limit}',
array(
'id_member' => $user_info['id'],
'exclude_boards' => $exclude_boards,
'query_see_board' => $user_info['query_wanna_see_board'],
'limit' => (int) $num_recent,
)
);
$posts = array();
$colorids = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
{
$row['body'] = strip_tags(strtr(parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']), array('<br />' => '&#10;')));
if ($smcFunc['strlen']($row['body']) > 128)
$row['body'] = $smcFunc['substr']($row['body'], 0, 128) . '...';

// Censor the subject.
censorText($row['subject']);
censorText($row['body']);

//Collect the color ids :)
$colorids[$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'] . '.gif') ? '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' => shorten_subject($row['subject'], 25),
'preview' => $row['body'],
'time' => timeformat($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'] . '.gif" align="middle" alt="' . $row['icon'] . '" border="0" />',
'views' => $row['num_views'],
'replies' => $row['num_replies'],
);
}
$smcFunc['db_free_result']($request);

// Load recent topic posts colors =)
if(!empty($colorids) && sp_loadColors($colorids) !== false)
foreach($posts as $k => $p)
if(!empty($color_profile[$p['poster']['id']]['link']))
$posts[$k]['poster']['link'] = $color_profile[$p['poster']['id']]['link'];

$context['recent_topics']=$posts;

// Just return it.
if (empty($posts))
return $posts;

echo '
<div class="tborder">
<table cellspacing="0" width="100%">
<tr class="catbg">
<td valign="middle"><img src="YOUR URL" border="0" /></td>
<td valign="middle" width="100%" style="padding: 5px;"> YOUR TEXT
</tr>
<tr>
<td style="padding: 5px;">
</td>';
foreach ($posts as $post)
echo '
<tr>
<td align="center" valign="middle" nowrap="nowrap">
', $post['icon'], '
</td>
<td valign="middle" width="%100">
<div style="font-size: 12px;"><b>
<a href="', $post['href'], '">', $post['subject'], '</a>
', $post['new'] ? '' : '<a href="' . $scripturl . '?topic=' . $post['topic'] . '.msg' . $post['new_from'] . ';topicseen#new"><img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/new.gif" alt="' . $txt['new'] . '" border="0" /></a>', '</b></div><div style="font-size: 9px;">Posted by ', $post['poster']['link'], ' in ', $post['board']['link'], ' | ', $post['time'], '
<div style="font-size: 9px;">
<i>(Visits: ', $post['views'], ' | Comments: ', $post['replies'], ')</i></font>
</td>
</tr>';
echo '
</table></div>';

Here is the code (with mod for Thank-o-matic)
Code: [Select]
global $context, $settings, $scripturl, $txt;
global $user_info, $modSettings, $smcFunc, $posts;
global $color_profile;

$exclude_boards = null;
$num_recent = !empty($parameters[0]) ? $parameters[0] :  (isset($_GET['limit']) ? (int) $_GET['limit'] : 5);

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

// Find all the posts in distinct topics.  Newer ones will have higher IDs.
$request = $smcFunc['db_query']('','
SELECT
m.poster_time, ms.subject, m.thank_you_post_counter, m.id_topic, m.id_member, m.id_msg, b.id_board, t.num_replies, t.num_views, b.name AS bName,
IFNULL(mem.real_name, m.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)) >= m.id_msg_modified AS is_read,
IFNULL(lt.id_msg, IFNULL(lmr.ID_MSG, -1)) + 1 AS new_from') . ', LEFT(m.body, 384) AS body, m.smileys_enabled, m.icon
FROM ({db_prefix}messages AS m, {db_prefix}topics AS t, {db_prefix}boards AS b, {db_prefix}messages AS ms)
LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.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:id_member})
LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = b.id_board AND lmr.id_member = {int:id_member})' : '') . '
WHERE t.ID_LAST_MSG >= ' . ($modSettings['maxMsgID'] - 35 * min($num_recent, 5)) . '
AND t.id_last_msg = m.id_msg
AND b.id_board = t.id_board' . (empty($exclude_boards) ? '' : '
AND b.id_board NOT IN ({array_int:exclude_boards})'). '
AND {raw:query_see_board}
AND ms.id_msg = t.id_last_msg
ORDER BY t.id_last_msg DESC
LIMIT {int:limit}',
array(
'id_member' => $user_info['id'],
'exclude_boards' => $exclude_boards,
'query_see_board' => $user_info['query_wanna_see_board'],
'limit' => (int) $num_recent,
)
);
$posts = array();
$colorids = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
{
$row['body'] = strip_tags(strtr(parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']), array('<br />' => '&#10;')));
if ($smcFunc['strlen']($row['body']) > 128)
$row['body'] = $smcFunc['substr']($row['body'], 0, 128) . '...';

// Censor the subject.
censorText($row['subject']);
censorText($row['body']);

//Collect the color ids :)
$colorids[$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'] . '.gif') ? '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' => shorten_subject($row['subject'], 25),
'preview' => $row['body'],
'time' => timeformat($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'] . '.gif" align="middle" alt="' . $row['icon'] . '" border="0" />',
'views' => $row['num_views'],
'replies' => $row['num_replies'],
'thankyou' => $row['thank_you_post_counter'],
);
}
$smcFunc['db_free_result']($request);

// Load recent topic posts colors =)
if(!empty($colorids) && sp_loadColors($colorids) !== false)
foreach($posts as $k => $p)
if(!empty($color_profile[$p['poster']['id']]['link']))
$posts[$k]['poster']['link'] = $color_profile[$p['poster']['id']]['link'];

$context['recent_topics']=$posts;

// Just return it.
if (empty($posts))
return $posts;

echo '
<div class="tborder">
<table cellspacing="0" width="100%">
<tr class="catbg">
<td valign="middle"><img src="YOUR URL" border="0" /></td>
<td valign="middle" width="100%" style="padding: 5px;"> YOUR TEXT
</tr>
<tr>
<td style="padding: 5px;">
</td>';
foreach ($posts as $post)
echo '
<tr>
<td align="center" valign="middle" nowrap="nowrap">
', $post['icon'], '
</td>
<td valign="middle" width="%100">
<div style="font-size: 12px;"><b>
<a href="', $post['href'], '">', $post['subject'], '</a>
', $post['new'] ? '' : '<a href="' . $scripturl . '?topic=' . $post['topic'] . '.msg' . $post['new_from'] . ';topicseen#new"><img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/new.gif" alt="' . $txt['new'] . '" border="0" /></a>', '</b></div><div style="font-size: 9px;">Posted by ', $post['poster']['link'], ' in ', $post['board']['link'], ' | ', $post['time'], '
<div style="font-size: 9px;">
<i>(Visits: ', $post['views'], ' | Comments: ', $post['replies'], ' | Thank you: ', $post['thankyou'], ')</i></font>
</td>
</tr>';
echo '
</table></div>';;


Hope you like it  ;D

EDIT: Oh! It's for SMF 2.0. Don't know if it works on SMF 1.1.x though.
Title: Re: [MOD] A Better Recent Topics
Post by: fotografo74 on March 04, 2009, 09:30:17 AM
Thanks :-)
Can you please attach bigger example image ?
Antonio
Title: Re: [MOD] A Better Recent Topics
Post by: Blue on March 04, 2009, 07:57:58 PM
Yes I can António. Here it is ;)
Title: Re: [MOD] A Better Recent Topics
Post by: fotografo74 on March 05, 2009, 02:35:43 AM
Yes I can António. Here it is ;)
Thanks!
It's a nice Mod ! :-)
Antonio
Title: Re: [MOD] A Better Recent Topics
Post by: Blue on March 05, 2009, 03:45:47 PM
Thanks :) It's my first mod eheh! :P

Is it working fine with you? ;)
Title: Re: A Better Recent Topics
Post by: necrit on April 28, 2009, 06:35:58 PM
So this is all very hard coded then?  Will there be anyway to specify the boards wanted by using the convenient block edit section of the configuration panel?  Figured it out.  my post is in the custom coding section http://simpleportal.net/index.php?topic=2132.0 (http://simpleportal.net/index.php?topic=2132.0)
Title: Re: A Better Recent Topics
Post by: SAFAD on April 12, 2010, 01:30:41 AM
it says wrong code
even when iparsed it in standalone php file
maybe its bug in simpleportal ?
Title: Re: A Better Recent Topics
Post by: Afro on April 30, 2010, 10:55:13 AM
This is a very nice twist.

Is there a way to remove the "RE" prefix in front of updates topics ?
Title: Re: A Better Recent Topics
Post by: SteveW on November 21, 2010, 06:05:43 AM
Hi - this is a very good block! :)

I would like to display this block in a table but I am struggling to alter the original code to fit into these:

Code: [Select]
<table align="center" border="0" cellpadding="1" cellspacing="1" style="width: 100%;">
<tbody>
<tr>
<td style="text-align: center;">
CODE 1</td>
<td style="text-align: center;">
CODE 2</td>
</tr>
<tr>
<td style="text-align: center;">
CODE 3</td>
<td style="text-align: center;">
CODE 4</td>
</tr>
<tr>
<td style="text-align: center;">
CODE 5</td>
<td style="text-align: center;">
CODE 6</td>
</tr>
</tbody>
</table>


I have given it a go but if someone can help that would be fantastic!  ;)
Title: Re: A Better Recent Topics
Post by: NCSurfer on July 09, 2011, 09:48:33 AM
How do I change the color of the text in Point 7 without making the changes throughout the entire theme.

I tried... <td valign="middle" width="100%" color="red" style="padding: 5px;">
Title: Re: A Better Recent Topics
Post by: Blue on July 09, 2011, 10:39:46 AM
Replace with:

Code: [Select]
<td valign="middle" width="100%" style="color:red;padding: 5px;">
Title: Re: A Better Recent Topics
Post by: NCSurfer on July 09, 2011, 10:47:17 AM
Worked great, ty
Title: Re: A Better Recent Topics
Post by: gumis_rulez on September 22, 2011, 03:23:46 PM
I am interested in adding only point 5 from your list:

Quote
5- How many people comment?

What should i change and in which file (because this information i didn;t find).

Maybe you could help me with these ads to recent topics:http://simpleportal.net/index.php?topic=9731.0
SimplePortal 2.3.8 © 2008-2024, SimplePortal