TinyPortal

Development => Block Codes => Topic started by: akulion on August 19, 2006, 04:05:50 PM

Title: 'In The News' - Block [Posts from a specific board]
Post by: akulion on August 19, 2006, 04:05:50 PM
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

(https://www.tinyportal.net/proxy.php?request=http%3A%2F%2Fimg78.imageshack.us%2Fimg78%2F5024%2Fawc7bl2.jpg&hash=6354e36be7ecbdd080546178c734c19a1a79fd91)

Live Demo

Click here (http://path-to-peace.com/forum2/)

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

(https://www.tinyportal.net/proxy.php?request=http%3A%2F%2Fpath-to-peace.net%2Fmisc%2Fextra.gif&hash=df15160f5650768e8e3be04af5359fd8d6cba758)

(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
Title: Re: 'In The News' - Block [Posts from a specific board]
Post by: JPDeni on August 19, 2006, 04:18:44 PM
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.
Title: Re: 'In The News' - Block [Posts from a specific board]
Post by: akulion on August 19, 2006, 04:21:03 PM
wow thanks for the tip i didn know that!
Title: Re: 'In The News' - Block [Posts from a specific board]
Post by: RoarinRow on August 19, 2006, 04:21:30 PM
That's very cool.  I'll have to try this out.   :up:
Title: Re: 'In The News' - Block [Posts from a specific board]
Post by: iowamf on August 19, 2006, 06:58:38 PM
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.
Title: Re: 'In The News' - Block [Posts from a specific board]
Post by: akulion on August 19, 2006, 07:23:32 PM
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
Title: Re: 'In The News' - Block [Posts from a specific board]
Post by: JPDeni on August 19, 2006, 08:15:09 PM
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.
Title: Re: 'In The News' - Block [Posts from a specific board]
Post by: akulion on August 19, 2006, 08:41:54 PM
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
Title: Re: 'In The News' - Block [Posts from a specific board]
Post by: akulion on August 19, 2006, 08:53:50 PM
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
Title: Re: 'In The News' - Block [Posts from a specific board]
Post by: JPDeni on August 19, 2006, 08:55:59 PM
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. :)
Title: Re: 'In The News' - Block [Posts from a specific board]
Post by: Greenbug on September 02, 2006, 05:22:11 PM
Can I select two topics from 3 different boards? If so how...

This is a great snippet
Title: Re: 'In The News' - Block [Posts from a specific board]
Post by: G6Cad on September 02, 2006, 05:45:40 PM
In Tp V.086 that is no option, but in the next release you will have 5 diffrent options to use.
TP V.086 only have one forum and one article, or just one or the other.
Title: Re: 'In The News' - Block [Posts from a specific board]
Post by: Greenbug on September 02, 2006, 05:53:27 PM
Ah yes. The NEW and improved TP. When is this scheduled to come out again. I hear its close...

Thanks,

GB
Title: Re: 'In The News' - Block [Posts from a specific board]
Post by: G6Cad on September 02, 2006, 05:57:00 PM
One day longer for every question asked about when it's released, so now it got delayed again  ;)
Title: Re: 'In The News' - Block [Posts from a specific board]
Post by: Greenbug on September 02, 2006, 05:59:02 PM
Oh thats just mean!!

No mercy you, no mercy
Title: Re: 'In The News' - Block [Posts from a specific board]
Post by: G6Cad on September 02, 2006, 06:17:55 PM
Im Swedish, dont know the word mercy  >:D
Title: Re: 'In The News' - Block [Posts from a specific board]
Post by: akulion on September 08, 2006, 08:14:27 AM
greenbug if you want to select posts from more thn 1 board u can add the board numbers to the line in the code as follows:

$result=ssi_recentTopicsINC(5,array(X,Y,Z),'return');

where X, Y and Z represent board numbers from which the news items wil be picked up automatically when someone posts in there.

Title: Re: 'In The News' - Block [Posts from a specific board]
Post by: -TMG- on November 04, 2006, 10:04:48 PM
hiho its a really cool block....

but is it somehow possible to get lets say the first 100 letters from the "news" itself to be displayed under the headline?!?!?!
Title: Re: 'In The News' - Block [Posts from a specific board]
Post by: akulion on November 04, 2006, 10:10:10 PM
yup there is but i have no clue how lol
Title: Re: 'In The News' - Block [Posts from a specific board]
Post by: Golin on March 02, 2007, 01:14:52 PM
The live demo link referes to a 'we have moved the site' page, which in turn referes to a page saying the forum is ported to vBulletin succesfully....
Title: Re: 'In The News' - Block [Posts from a specific board]
Post by: G6Cad on March 02, 2007, 01:48:47 PM
Yes, Aku have converted his main forum to PhBB, but he is still using SMF and TP to test and keep up to date so he can still give you support on it ;)
Title: Re: 'In The News' - Block [Posts from a specific board]
Post by: akulion on March 04, 2007, 06:35:20 AM
oh sorry about that changed the link

the site is still up under forum2
Title: Re: 'In The News' - Block [Posts from a specific board]
Post by: Gourgi on March 04, 2007, 10:09:24 AM
 :coolsmiley:
not found ...
Title: Re: 'In The News' - Block [Posts from a specific board]
Post by: akulion on March 04, 2007, 11:40:04 AM
oohh yea i forgot to change the .net to .com

now fixed for sure
Title: Re: 'In The News' - Block [Posts from a specific board]
Post by: Golin on March 04, 2007, 02:38:38 PM
yeah fixed :) thanks for quick response.
Title: Re: 'In The News' - Block [Posts from a specific board]
Post by: eline on February 16, 2008, 12:24:55 AM
Gobo
What mod / snippet do You use for nice ajax mod to have tabbed menu with news ?
Title: Re: 'In The News' - Block [Posts from a specific board]
Post by: Ken. on February 16, 2008, 12:48:39 AM
eline if you do a search here on TP for "tabbed menu" you'll find the threads that give details on how to do the menu you see on his site.  :)
Title: Re: 'In The News' - Block [Posts from a specific board]
Post by: eline on February 16, 2008, 01:44:48 AM
Tx Ken
I see You use also it ;)

I found few solutions as "Tab menu" and code this one with moo libraries - I love them and will code it for my self.
I suspect "mod" code, but I can do it myself.

I just did as a snippets
users online with avatars,
last users with avatars,
last photos form members ulitmate profile,
my buddys online,
and works on others

regards
Title: Re: 'In The News' - Block [Posts from a specific board]
Post by: durgia on December 14, 2008, 01:06:45 AM
I apologize for bringing up the dead topic, but I just found this and I love the feature!

I don't know very much about PHP but is it at all possible to do the following with this?

Reverse the displayed order? (Instead of going 1,2,3,4,5 I want to go 5,4,3,2,1) Where the lower number is the newer post.

It would be neat to have one of these compare to the calendar for upcoming events too but thats a whole other story :P
Title: Re: 'In The News' - Block [Posts from a specific board]
Post by: ZarPrime on December 14, 2008, 02:53:23 AM
The link to the demo gives an error 404 - page not found.  However, Aku, I enjoyed your error 404 page with the frog very much.
Title: Re: 'In The News' - Block [Posts from a specific board]
Post by: IchBin on December 14, 2008, 03:39:05 AM
Find:
ORDER BY t.ID_LAST_MSG DESC

Change to:
ORDER BY t.ID_LAST_MSG ASC
Title: Re: 'In The News' - Block [Posts from a specific board]
Post by: durgia on December 14, 2008, 05:24:10 PM
Thank You, it works perfectly now!
Title: Re: 'In The News' - Block [Posts from a specific board]
Post by: Dianna on February 25, 2009, 04:13:58 AM
TP: v1.0.5. beta 1
SMF: v1.1.7
www.schreeandbaby.com/updates

Hi guys! This is one of the exact snippets I was looking for to show latest news from one of the forum categories. I have something weird happening. I've indicated that I wanted the last 8 posts to show. It's only showing the last 2 posts.  It's the 2nd block on the right side on my site.

Here's my coding that I tweaked to fit my site's design. I'm wondering if there is some ROW height that I'm missing either in this coding or in the SSI coding that I was instructed to include in the ssi.php in the root directory.

Here's my edited php block, anything you guys can see?:

echo' <div align="center">
<table border="0" width="140" id="table1">
<tr>
<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(8,array(5.0),'return');
foreach($result as $my){

  echo "$bullet";
  echo '<span class="smalltext">'.$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">Latest On Your Mind News <a href="http://www.schreeandbaby.com/updates/index.php?board=5.0">From the OYM News Section</a></font></td>
</tr>
</table>
</div>';



Title: Re: 'In The News' - Block [Posts from a specific board]
Post by: ZarPrime on February 25, 2009, 05:09:17 AM
Dianna,

One of our coders will probably have to take a look at this when they are on.  I can do some basic things with php but I'm not that great with it.

In the meantime, can you amend your post above to place the code inside of code tags.  The reason for this is because when it is place like you have it, some code is sometimes missed.  To do that, Paste your code into your message and highlight the code.  Then select the code button (the one with the # on it).

After you do this, it will look more like this ...

Your Code here


Thanks,
ZarPrime
Title: Re: 'In The News' - Block [Posts from a specific board]
Post by: Dianna on February 25, 2009, 07:16:14 AM
Awww, thanks ZarPrime, my bad, I just fixed it and put the code into the box.
Title: Re: 'In The News' - Block [Posts from a specific board]
Post by: ZarPrime on February 26, 2009, 12:53:25 PM
Diana,

I notice that none of our coders has responded here yet, so I will mention it to them.  As I said, I'm not too good with this stuff but I looked through your code to make sure you didn't have any open tags or anything but nothing jumped out at me.

In the meantime, assuming you made the changes to the ssi file specified in the first post in this topic, the only thing you might try is to change ...

$result=ssi_recentTopicsINC(8,array(5.0),'return');

to

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

and see if that makes a difference.

ZarPrime
Title: Re: 'In The News' - Block [Posts from a specific board]
Post by: JPDeni on February 26, 2009, 02:19:23 PM
Sorry I didn't get here sooner. I was asleep. :)

I reformatted the code so I could follow it a little easier. I noticed that you had your opening span tag inside the "foreach" loop, but the closing tag outside of it. I don't know if that would make a difference or not. Also, ZarPrime's suggestion to use the number without the ".0" is good.


global $context, $scripturl;

$bullet = '<img src="'.$settings['images_url'].'/TPdivider.gif" alt="" border="0" style="margin:0 2px 0 0;" />';
$result=ssi_recentTopicsINC(8,array(5),'return');

echo' <div align="center">
<table border="0" width="140" id="table1">
  <tr>
    <td><font face="Verdana">';

foreach($result as $my){
echo "$bullet";
echo '<span class="smalltext">'.$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">Latest On Your Mind News <a href="http://www.schreeandbaby.com/updates/index.php?board=5.0">From the OYM News Section</a></font></td>
</tr>
</table>
</div>';


Otherwise, I don't see a problem with the code.

I couldn't access the page. Looks like it's been moved. The only other possibility I can think of for it only showing 2 posts is that maybe you only have 2 topics. Realize that this is a recent topics function, so it will only show once for each topic.
Title: Re: 'In The News' - Block [Posts from a specific board]
Post by: ZarPrime on February 26, 2009, 02:28:28 PM
Thanks JPD. :up:

ZarPrime