TinyPortal

Development => Block Codes => Topic started by: Dragooon on July 26, 2007, 11:59:21 AM

Title: Custom Recent Topics block.[2nd Update!]
Post by: Dragooon on July 26, 2007, 11:59:21 AM
Hello, Your old noob is back :P
But this time I am not asking something.I was roaming around TP forums and found quite a few requests about this block so decided to make it.
It can :
- Show topic name and link
- Show some body part of it(can be customized on how much you want to show).
- Show where the topic is posted.
- Can be customized on how many topics you want to show.
- Can be made so that it shows topics from only 1 specified boards.
Updated!
- Now fixed the user group error.Now they will see what they can see.
Update No. 2!
- Now fixed the code so that it doesent shows topics from a recycle thread board

Main source code to be entered in a Center php block(Using left or right will mess it up) :
//Custom Recent posts
//Made by Dragooon
global $scripturl, $db_prefix, $context, $smfFunc, $txt, $user_info, $modSettings;
//Main query
$result = db_query("
SELECT
m.id_msg, m.subject, m.body, t.id_topic, t.id_board,
b.name AS bname,m.id_member,b.memberGroups
FROM {$db_prefix}topics AS t, {$db_prefix}messages AS m, {$db_prefix}members AS mem, {$db_prefix}boards AS b
WHERE t.id_board = b.id_board
AND m.id_msg = t.id_first_msg
AND mem.id_member = m.id_member
AND b.memberGroups = b.memberGroups
AND $user_info[query_see_board]
AND ID_BOARD != $modSettings[recycle_board]
ORDER BY t.id_topic  DESC
LIMIT 5") or die(mysql_error());

while ($row = mysql_fetch_assoc($result))
{      //The variable which decides the MAX letters it can have.
$bodylen = 200;
// Limit the length of the message, if the option is set.
if (strlen(str_replace('<br />', "\n", $row['body'])) > $bodylen)
$row['body'] = htmlspecialchars(substr(str_replace('<br />', "\n", un_htmlspecialchars($row['body'])), 0, $bodylen-3) . '...', ENT_QUOTES);


censorText($row['body']);
censorText($row['subject']);

$context['rp'][] = array(
'title' => $row['subject'],
'link' => $scripturl . '?topic=' . $row['id_topic'] . '.0',
'description' => $row['body'],
'category' =>  $scripturl .'?board=' .$row['id_board'] . '.0',
'bname' => $row['bname']
);
}
foreach( $context['rp'] as $info)
echo'
<dt><br><a href="', $info['link'], '">', $info['title'], '</a></dt>
<dd>', $info['description'], '<br>posted in <a href ="',$info['category'],'">',$info['bname'],'</a></dd>
</dlv>';


This code will show 5 recent posts from any board.Its maximum letter limit would be 200 if crossed it will be "...".

Customization :
To limit the number of topics shown:
See that LIMIT 5 and edit the 5 to no. of posts you want.

To show posts from 1 board.
See that t.id_board = b.id_board.Edit it and change it to t.id_board = <Your Board ID> AND b.id_board = <Your Board ID>
Make the Board ID to match the ID of the board you want to show.Remember BOTH entries must be same.

To limit the length of max body letters which can be shown:
Find $bodylen = 200; and edit 200 with what you want.

Well I hope you like it.

I made it with help of a Post that Thantos made in SMF community
Title: Re: Custom Recent Topics block.
Post by: Ken. on July 26, 2007, 12:04:33 PM
Thanks Dragooon this sounds good, we'll have to give it a try.  :)
Title: Re: Custom Recent Topics block.
Post by: Dragooon on July 26, 2007, 12:10:45 PM
Hehe Good luck
Title: Re: Custom Recent Topics block.[Updated]
Post by: Dragooon on July 26, 2007, 05:35:06 PM
Ok I updated this thing.I fixed the fact that the members or guests were able to see posts from boards which they dont have access to.
Title: Re: Custom Recent Topics block.[2nd Update!]
Post by: Dragooon on July 27, 2007, 04:57:37 AM
Updated again!
Fixed the thing so that it doesent shows topics from a thrash board.
Title: Re: Custom Recent Topics block.[2nd Update!]
Post by: MeRcChRiS on August 04, 2007, 08:42:35 AM
Im getting a Internal Server error when I add this code to a centered php block.
Title: Re: Custom Recent Topics block.[2nd Update!]
Post by: knat on August 04, 2007, 10:42:07 AM
im getting Page Not Found when i add this  :P

Maybe this only works for latest versions of SMF & TP  ::)
Title: Re: Custom Recent Topics block.[2nd Update!]
Post by: Dragooon on August 04, 2007, 12:44:24 PM
It is working for me fine here.
Title: Re: Custom Recent Topics block.[2nd Update!]
Post by: celdric on September 06, 2007, 12:33:00 PM
Hi.  :) This sounds like a good mod.  Although have problems with the customizing.

I did it the way below.  31.0 is the board id

I edited
WHERE t.id_board = 31.0 AND b.id_board = 31.0


and

WHERE t.id_board = <31.0> AND b.id_board = <31.0>

Either way it does not work. Well, I suppose that I misunderstand your post. Can you please post an example?  :)
Title: Re: Custom Recent Topics block.[2nd Update!]
Post by: Dragooon on September 06, 2007, 01:00:03 PM
What was the full thing you did?
Can I see the full code you added?
Title: Re: Custom Recent Topics block.[2nd Update!]
Post by: celdric on September 07, 2007, 01:55:45 PM
Hi. I just changed a line. I seperated it in the codebox. English isn't my mothertounge, sorry. So perhaps I messed it up.

//Custom Recent posts
//Made by Dragooon
global $scripturl, $db_prefix, $context, $smfFunc, $txt, $user_info, $modSettings;
//Main query
$result = db_query("
SELECT
m.id_msg, m.subject, m.body, t.id_topic, t.id_board,
b.name AS bname,m.id_member,b.memberGroups
FROM {$db_prefix}topics AS t, {$db_prefix}messages AS m, {$db_prefix}members AS mem, {$db_prefix}boards AS b
           






WHERE t.id_board = 31.0 AND b.id_board = 31.0









AND m.id_msg = t.id_first_msg
AND mem.id_member = m.id_member
AND b.memberGroups = b.memberGroups
AND $user_info[query_see_board]
AND ID_BOARD != $modSettings[recycle_board]
ORDER BY t.id_topic  DESC
LIMIT 5") or die(mysql_error());

while ($row = mysql_fetch_assoc($result))
{      //The variable which decides the MAX letters it can have.
$bodylen = 200;
// Limit the length of the message, if the option is set.
if (strlen(str_replace('<br />', "\n", $row['body'])) > $bodylen)
$row['body'] = htmlspecialchars(substr(str_replace('<br />', "\n", un_htmlspecialchars($row['body'])), 0, $bodylen-3) . '...', ENT_QUOTES);


censorText($row['body']);
censorText($row['subject']);

$context['rp'][] = array(
'title' => $row['subject'],
'link' => $scripturl . '?topic=' . $row['id_topic'] . '.0',
'description' => $row['body'],
'category' =>  $scripturl .'?board=' .$row['id_board'] . '.0',
'bname' => $row['bname']
);
}
foreach( $context['rp'] as $info)
echo'
<dt><br><a href="', $info['link'], '">', $info['title'], '</a></dt>
<dd>', $info['description'], '<br>posted in <a href ="',$info['category'],'">',$info['bname'],'</a></dd>
</dlv>';