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

Recent

Welcome to TinyPortal. Please login or sign up.

March 29, 2024, 05:01:59 AM

Login with username, password and session length
Members
Stats
  • Total Posts: 195,105
  • Total Topics: 21,213
  • Online today: 310
  • Online ever: 3,540 (September 03, 2022, 01:38:54 AM)
Users Online
  • Users: 1
  • Guests: 302
  • Total: 303
  • lurkalot

'In The News' - Block [Posts from a specific board]

Started by akulion, August 19, 2006, 04:05:50 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

akulion

Hi

Ok this is a snippet which requires 2 things:

1. An addition to SSI.php file located in your forum root folder
2. Adding a board called "In the News" to your existing forum

Or alternatively for #2 you can specify any board you want in the array itself.

What does it do?

It takes the posts from a specified board and displays the latest threads there.

The reason I have named it "In the News" block is beause I personally use it on my forum to display the latest nternational headlines from around the Globe, giving my members an added incentive to keep coming back since the site becomes their 'one stop for the news and fun and other stuff'

Screen Shot



Live Demo

Click here

Anyways on to it....

Install Instructions....

1. Download your SSI.php file from your forum root and make a backup

2. Open the SSI.php and look for this line:



// Show the top poster's name and profile link.



Add this BEFORE that line



// Recent topic list reversed:   [board] Subject by Poster Date
function ssi_recentTopicsINC($num_recent = 8, $include_boards = null, $output_method = 'echo')
{
global $context, $settings, $scripturl, $txt, $db_prefix, $ID_MEMBER, $user_info, $modSettings;

$include_boards = empty($include_boards) ? array() : $include_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 = db_query("
SELECT
m.posterTime, ms.subject, m.ID_TOPIC, m.ID_MEMBER, m.ID_MSG, b.ID_BOARD, b.name AS bName,
IFNULL(mem.realName, m.posterName) AS posterName, " . ($user_info['is_guest'] ? '1 AS isRead, 0 AS new_from' : '
IFNULL(lt.ID_MSG, IFNULL(lmr.ID_MSG, 0)) >= m.ID_MSG_MODIFIED AS isRead,
IFNULL(lt.ID_MSG, IFNULL(lmr.ID_MSG, -1)) + 1 AS new_from') . ", LEFT(m.body, 384) AS body, m.smileysEnabled, 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 = $ID_MEMBER)
LEFT JOIN {$db_prefix}log_mark_read AS lmr ON (lmr.ID_BOARD = b.ID_BOARD AND lmr.ID_MEMBER = $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($include_boards) ? '' : "
AND b.ID_BOARD IN (" . implode(', ', $include_boards) . ")") . "
" . ((!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0) ? "
AND b.ID_BOARD != '$modSettings[recycle_board]'" : '') . "
AND $user_info[query_see_board]
AND ms.ID_MSG = t.ID_FIRST_MSG
ORDER BY t.ID_LAST_MSG DESC
LIMIT $num_recent", __FILE__, __LINE__);
$posts = array();
while ($row = mysql_fetch_assoc($request))
{
$row['body'] = strip_tags(strtr(parse_bbc($row['body'], $row['smileysEnabled'], $row['ID_MSG']), array('<br />' => '')));
if (strlen($row['body']) > 128)
$row['body'] = substr($row['body'], 0, 128) . '...';

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

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['posterName'],
'href' => empty($row['ID_MEMBER']) ? '' : $scripturl . '?action=profile;u=' . $row['ID_MEMBER'],
'link' => empty($row['ID_MEMBER']) ? $row['posterName'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] . '">' . $row['posterName'] . '</a>'
),
'subject' => $row['subject'],
'short_subject' => shorten_subject($row['subject'], 25),
'preview' => $row['body'],
'time' => timeformat($row['posterTime']),
'timestamp' => forum_time(true, $row['posterTime']),
'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['isRead']),
'new_from' => $row['new_from'],
'icon' => '<img src="' . $settings[$icon_sources[$row['icon']]] . '/post/' . $row['icon'] . '.gif" align="middle" alt="' . $row['icon'] . '" border="0" />',
);
}
mysql_free_result($request);

// Just return it.
if ($output_method != 'echo' || empty($posts))
return $posts;

echo '
<table border="0" class="ssi_table">';
foreach ($posts as $post)
echo '
<tr>
<td align="right" valign="top" nowrap="nowrap">
[', $post['board']['link'], ']
</td>
<td valign="top">
<a href="', $post['href'], '">', $post['subject'], '</a>
', $txt[525], ' ', $post['poster']['link'], '
', $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[302] . '" border="0" /></a>', '
</td>
<td align="right" nowrap="nowrap">
', $post['time'], '
</td>
</tr>';
echo '
</table>';
}




3. Save file and upload to your server and replace the SSI.php

4.Save the image below and place it in your forum root



(or alternatively you can use another image if you prefer)

5. Create a PHP box from your TP admin panel under blocks

6. Insert the following code* to the block, set permissions, submit and activate.



echo' <div align="center">
<table border="1" width="100%" id="table1">
<tr>
<td width="100" valign="top" bgcolor="#FFFFFF">
<font face="Verdana">
<img border="0" src="extra.gif" width="100" height="111"></font><p align="center">
<font size="1" face="Verdana">Read, post and discuss the latest news from around the
world in our forums!</font></p>
<p align="center"><font size="1" face="Verdana">Get all the details by comparing views!</font></td>
<td><font face="Verdana">';

global $context, $scripturl;
$bullet = '<img src="'.$settings['images_url'].'/TPdivider.gif" alt="" border="0" style="margin:0 2px 0 0;" />';
$result=ssi_recentTopicsINC(5,array(58),'return');
foreach($result as $my){

  echo "$bullet";
  echo '<span class="largetext">'.$my['link'];
  // is this topic new? (assume they are logged in)
if (!$my['new'] && $context['user']['is_logged'])
echo '
                                                <a href="', $scripturl, '?topic=', $my['topic'], '.from', $my['newtime'], '#new"><img src="', $settings['images_url'], '/', $context['user']['language'], '/new.gif" alt="', $txt[302], '" border="0" /></a>';
echo '<hr>';
}
echo '</span>';

echo'   <br></font><font size="1" face="Verdana">The News is updated
when members make new posts in the <a href="http://www.yoursite.com/link_to_your_newsboard">In the News Section</a> Please be sure
to <a href="http://www.yoursite.com/if_u_have_posting_rules_give_link_here">read posting rules</a> for that board before posting!</font></td>
</tr>
</table>
</div>';



* Make the following changes to the code above to suit your needs....

In the code above set the board number you want the news to be picked up from and also how many posts to show

$result=ssi_recentTopicsINC(5,array(58),'return');

5 = number of topics to display
58 = board number

Also change the 2 links for the board URL and Posting Rules according to ur needs (or else u can remove it altogether if not needed)

***The End***

Credits for this go to Oldiesman and iowamf

JPDeni

Very cool! And I like that you have actual *news* on your site.

If folks didn't want to alter the SSI.php file -- and if they were only going to use the function in this block -- they could put the function in the block itself. They can just paste it at the end of the display code.

akulion


RoarinRow

That's very cool.  I'll have to try this out.   :up:

SMF 2.0 RC3
TP 1.0 beta 5-1
Wordpress 3.0

iowamf

looks good - glad to see this in use somewhere else.

One additional benefit of adding the ssi_recentTopicsINC function is that you don't have to update the call to it everytime you modify your forums. The original function only took "excluded boards" as a parameter, which means if only want information from one board - you'd have to update a long list of board numbers everytime you add a board.

nice summary too.

akulion

im trying to figure out how NOT to repeat the topics as 'new' if someone posts in them

if anyone has an idea please do share

basically like bloc's recent topics..they dont repeat even if new posts are made
but this one does repeat if someone makes a new post in the same topic

JPDeni

Try changing

ORDER BY t.ID_LAST_MSG DESC

to

ORDER BY t.ID_FIRST_MSG DESC

I'm not sure that'll do what you want, but it might.

akulion

nope dosent seem to do the trick

Bloc gave a clue in his 'recent topics' thread - it has something to do with sorting by 'creation date/time'

but ive been reading all the codes to find something with no luck so far

basically what i want to achieve is that once a topic is posted it appears in the block .... but it does not get bumped up when someone replies to it....

the only thing that can happen is that newer topics slowly knock it off the chart as they appear and once that topic is gone, it never returns in the block even if its gettin 1000 replies a second

akulion

hold on

it does do the trick

the reason i thought it didnt do it was cos i have the "merge double posts" mod installed...so it was basically merging my second post and bumping the topic up as a new topic

but i just replied to a topic in which someone else had posted and it didnt get bumped up :D

So it WORKS!!!

Thanks JPDeni :D

JPDeni

You're welcome. :)

I was really hoping that would do it because otherwise it would mean a whole lot of delving into that query statement. Messy stuff. :)