SimplePortal

Customization => Blocks and Modifications => Topic started by: Blue on July 01, 2011, 05:56:15 PM

Title: [Block] Recent Topics/Posts with Post Preview!
Post by: Blue on July 01, 2011, 05:56:15 PM
Recent Topics/Posts with Post Preview
[Made by Blue][I hope you like it =D]

Description: A block that previews the recent topics or posts with or without scrolling.

Requirements:
- SMF 2.0 GOLD
- Simple Portal 2.3.5

SETUP INSIDE:
+ Latest Topics OR Latest Messages
+ Number of posts
+ Number of characters to output
+ Scrolling Enable/Disable
+ Set height of the block for Scrolling
+ Set speed for Scrolling
+ Vertical scrollbar visible if you want
+ You can translate it to your own language with $text inside
+ Exclude boards that you want
+ HTMLSPECIALCHARS for languages that use special characters

Author Notes:
I've made a block for an user in the Block Requests and here it is ;) Suggestions are welcome :D

NEW VERSION:
1.1 -> BBCode and Hidden Boards fix
1.2 -> "New" image in topics/posts not read
1.3 -> Exclude boards that you want to hide from guests
1.4 -> Internet Explorer 8 fix (disable vertical scrollbar)
1.5 -> Permissons fix! (User only see what he is allowed to); Exclude boards for everyone and HTMLSPECIALCHARS to languages like Greek and bugfix.
1.6 -> Added Scrollbar option
1.7 -> Tweaked to show display names instead of usernames within the block (thanks to Sayaka Maizono (http://simpleportal.net/index.php?action=profile;area=summary;u=1))
1.8 -> Tweaked by GeorG (http://simpleportal.net/index.php?action=profile;u=10918) (1. Icon "NEW" disappears when the message has been read 2. Guests are shown author nick)
Code: [Select]
<?php

/*
Block: Recent posts with post preview
Author: Blue @ Simple Portal.net
Version: 1.8
*/

/* [SETUP WHAT YOU WANT HERE] */

$topics_posts 1; // TOPICS - 1 | MESSAGES - 2
$limit 5; // How many recent posts do you want to output?
$number 70; // How many characters do you want to output?
$exclude_boards null; // IF null guests can see all boards | IF you want to hide some boards use: array( ID1, ID2, ID3) where ID is the board's ID
$htmlspecialcharacters false// Do you need to show html special characters like Greek characters?

// Scroll Enable? Height and Speed?
$scrolling 0;       // ENABLE - 1 | DISABLE - 2
$speed 3;           // SLOW - 1 | MEDIUM - 10 | FAST - 20
$height "150px";
$scrollbar 0;       // ENABLE - 1 | DISABLE - 2

// Do you want to translate it to your own language? :P
$text['sportal_false'] = 'Simple Portal not found';

/* [STOP!] - THIS IS THE END OF SETUP */

//Only code from now on ;)
global $smcFunc$scripturl$sourcedir$modSettings$user_info$settings$context$txt;

// Lets see if you are using Simple Portal. If not...well...go get them :D
if (!file_exists($sourcedir '/PortalBlocks.php'))
{
echo $text['sportal_false'];
return;
}

// Let's grab some database results
if ($topics_posts == 1) {

if (is_array($exclude_boards) || (int) $exclude_boards === $exclude_boards)
{
$exclude_boards is_array($exclude_boards) ? $exclude_boards : array($exclude_boards);
}
elseif ($exclude_boards != null)
{
$output_method $exclude_boards;
$exclude_boards = array();
}

$posts_result $smcFunc['db_query']('''
   SELECT m.poster_time, m.id_msg, t.id_member_updated, m.subject, m.body, m.id_topic, b.name, t.id_last_msg, IFNULL(u.real_name, m.poster_name) AS poster_name, u.avatar, g.online_color,' 
. ($user_info['is_guest'] ? '1 AS is_read, 0 AS new_from' '
(IFNULL(lb.id_msg, 0) >= b.id_msg_updated) AS is_read,
IFNULL(lb.id_msg, -1) + 1 AS new_from'
) . '
   FROM {db_prefix}topics AS t
   LEFT JOIN {db_prefix}boards AS b ON (t.id_board = b.id_board)
   LEFT JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_last_msg)
   LEFT JOIN {db_prefix}members AS u ON (t.id_member_updated = u.id_member)' 
. ($user_info['is_guest'] ? '' '
   LEFT JOIN {db_prefix}log_boards AS lb ON (lb.id_board = b.id_board AND lb.id_member = {int:current_member})'
) . '
   LEFT JOIN {db_prefix}membergroups AS g ON (g.id_group = CASE WHEN u.id_group = 0 THEN u.id_post_group ELSE u.id_group END)
   ' 
. (!$user_info['is_guest'] ? '
LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = m.id_topic AND lt.id_member = ' 
$user_info['id'] . ')
LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = b.id_board AND lmr.id_member = ' 
$user_info['id'] . ')' '') . '     
   WHERE m.approved=1'   
. (empty($exclude_boards) ? '' '
AND b.id_board NOT IN ({array_int:exclude_boards})'
) . ' AND {query_see_board}
   ORDER BY t.id_last_msg DESC
   LIMIT ' 
$limit
array(
'exclude_boards' => empty($exclude_boards) ? '' $exclude_boards,
'current_member' => $user_info['id'],
)   
   );
$posts = array();
while (
$row_posts $smcFunc['db_fetch_assoc']($posts_result))
{

      global 
$memberContext;
      
loadMemberData($row_posts['id_member_updated']);
      
loadMemberContext($row_posts['id_member_updated']);

   
$posts[] = array(
  'id' => $row_posts['id_member_updated'],
      
'username' => '<a style="color: ' $row_posts['online_color'] . ';" href="' $scripturl '?action=profile;u=' $row_posts['id_member_updated'] . '">' $row_posts['poster_name'] . '</a>',
      
'subject' => '<a style="font-weight: bold;" title="' $txt['board'] . ':&nbsp;' $row_posts['name'] .'" href="' $scripturl '?topic=' $row_posts['id_topic'] . '.msg' $row_posts['id_last_msg'] . ';topicseen#new">' $row_posts['subject'] . '</a>',
      
'body' => $row_posts['body'],
  'avatar' => $row_posts['avatar'] == '' $memberContext[$row_posts['id_member_updated']]['avatar']['href'] : (stristr($row_posts['avatar'], 'http://') ? $row_posts['avatar'] : $modSettings['avatar_url'] . '/' $row_posts['avatar']),
  'board' => $row_posts['name'], 
  'time' => timeformat($row_posts['poster_time']),
  'new' => !empty($row_posts['is_read']),
      
'subject_new' => $scripturl '?topic=' $row_posts['id_topic'] . '.msg' $row_posts['id_msg'] . ';topicseen#new'
   
);
}
$smcFunc['db_free_result']($posts_result);

} else {

if (is_array($exclude_boards) || (int) $exclude_boards === $exclude_boards)
{
$exclude_boards is_array($exclude_boards) ? $exclude_boards : array($exclude_boards);
}
elseif ($exclude_boards != null)
{
$output_method $exclude_boards;
$exclude_boards = array();
}

$posts_result $smcFunc['db_query']('''
   SELECT m.poster_time, m.id_msg, m.id_member, m.subject, m.body, m.id_topic, b.name, b.id_board, IFNULL(u.real_name, m.poster_name) AS poster_name, u.avatar, g.online_color,' 
. ($user_info['is_guest'] ? '1 AS is_read, 0 AS new_from' '
(IFNULL(lb.id_msg, 0) >= b.id_msg_updated) AS is_read,
IFNULL(lb.id_msg, -1) + 1 AS new_from'
) . '
   FROM {db_prefix}messages AS m
   LEFT JOIN {db_prefix}boards AS b ON (m.id_board = b.id_board)
   LEFT JOIN {db_prefix}members AS u ON (m.id_member = u.id_member)' 
. ($user_info['is_guest'] ? '' '
   LEFT JOIN {db_prefix}log_boards AS lb ON (lb.id_board = b.id_board AND lb.id_member = {int:current_member})'
) . '
   LEFT JOIN {db_prefix}membergroups AS g ON (g.id_group = CASE WHEN u.id_group = 0 THEN u.id_post_group ELSE u.id_group END)
   ' 
. (!$user_info['is_guest'] ? '
LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = m.id_topic AND lt.id_member = ' 
$user_info['id'] . ')
LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = b.id_board AND lmr.id_member = ' 
$user_info['id'] . ')' '') . '   
   WHERE m.approved=1'   
. (empty($exclude_boards) ? '' '
AND b.id_board NOT IN ({array_int:exclude_boards})'
) . ' AND {query_see_board}
   ORDER BY m.id_msg DESC
   LIMIT ' 
$limit
array(
'exclude_boards' => empty($exclude_boards) ? '' $exclude_boards,
'current_member' => $user_info['id'],
)   
   );
$posts = array();
while (
$row_posts $smcFunc['db_fetch_assoc']($posts_result))
{

      global 
$memberContext;
      
loadMemberData($row_posts['id_member']);
      
loadMemberContext($row_posts['id_member']);

   
$posts[] = array(
  'id' => $row_posts['id_member'],
      
'username' => '<a style="color: ' $row_posts['online_color'] . ';" href="' $scripturl '?action=profile;u=' $row_posts['id_member'] . '">' $row_posts['poster_name'] . '</a>',
      
'subject' => '<a style="font-weight: bold;" title="' $txt['board'] . ':&nbsp;' $row_posts['name'] .'" href="' $scripturl '?topic=' $row_posts['id_topic'] . '.msg' $row_posts['id_msg'] . ';topicseen#new">' $row_posts['subject'] . '</a>',
      
'body' => $row_posts['body'],
  'avatar' => $row_posts['avatar'] == '' $memberContext[$row_posts['id_member']]['avatar']['href'] : (stristr($row_posts['avatar'], 'http://') ? $row_posts['avatar'] : $modSettings['avatar_url'] . '/' $row_posts['avatar']),
  'board' => $row_posts['name'],  
  'time' => timeformat($row_posts['poster_time']),
  'new' => !empty($row_posts['is_read']),
      
'subject_new' => $scripturl '?topic=' $row_posts['id_topic'] . '.msg' $row_posts['id_msg'] . ';topicseen#new'
   
);
}
$smcFunc['db_free_result']($posts_result);

}

//Finally the Output

//Scrolling xD
if ($scrolling == 1)
echo 
'<div style="overflow: hidden;"><marquee height=' $height ' behavior="scroll" direction="up" scrollamount="' $speed '" onmouseover="this.stop()" onmouseout="this.start()">';

if (
$scrollbar == 1)
echo 
'<div style="height:' $height '; overflow-y: scroll; overflow-x: hidden;">';

foreach (
$posts as $post) {

// Lets fix the BBCode bug and Strip the Text
$content1 str_replace("[""<"$post['body']);
$content2 str_replace("]"">"$content1); 
$content3 strip_tags($content2);
$preview substr ($content3,0,$number);

echo
'<table>
<tr>
<td style="width: 40px;">
<img src="' 
$post['avatar'] .'" alt="" width="40px" height="40px" />
</td>
<td>
$post['subject'];

if (!$post['new'] && $context['user']['is_logged'])
echo '&nbsp;<a href=' $post['subject_new'] . '><img src="'$settings['images_url'], '/'$context['user']['language'], '/new.gif" alt="new" border="0" /></a>';

echo '<br />
<small>' 
$txt['by'] . '&nbsp;' $post['username'] . '&nbsp;|&nbsp;' $post['time'] .'</small>
</td>
</tr>
</table>'
;

if ($htmlspecialcharacters) {
echo htmlspecialchars($previewENT_NOQUOTES"UTF-8") . '...';
} else {
echo $preview '...';
}

echo 
'<hr />';
}
        
//Scrolling xD
if ($scrollbar == 1)
echo 
'</div>'

if (
$scrolling == 1)
echo 
'</marquee></div>';
?>
Title: Re: [Block] Recent Posts with Post Preview!
Post by: Devil jimmy on July 01, 2011, 06:22:28 PM
not for 1.1.14 pity :|
such as the most presented custom made blocks here  :'(
Title: Re: [Block] Recent Posts with Post Preview!
Post by: Blue on July 01, 2011, 06:34:47 PM
SMF 2.0 is GOLD, You should upgrade ;)
Title: Re: [Block] Recent Posts with Post Preview!
Post by: Devil jimmy on July 01, 2011, 06:52:33 PM
I have a theme which is adapted
many mods that you can not find 2.0
Here and there some custom scripts specifically for my forum that I can not miss
I have a test forum with 2.0 but can not get it the way I want
so upgrading will not be for immediate
Title: Re: [Block] Recent Posts with Post Preview!
Post by: Blue on July 03, 2011, 11:40:30 AM
Code Updated. Now includes scrolling and on mouse over it stops (thanks to rocknroller)
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: Blue on July 03, 2011, 12:43:04 PM
Code Updated. Now it's possible to choose between Latest Topics or Latest Posts and Colors usernames according to Membergroup
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: amko_sa on July 03, 2011, 02:25:41 PM
Thank you Blue this is cool. 8)
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: grafitus on July 04, 2011, 08:29:27 AM
Good work! ;) But it would be fine if you use a single table; you can only <tr> tag for rows.
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: Blue on July 04, 2011, 08:43:30 AM
Thank you grafitus,

I didn't use only <tr> because I could not output the same way that is now because I wanted the $post['body'] out of the table and not in  :-[
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: S@ffz on July 04, 2011, 11:20:27 PM
Blue this is a great block thank you  ;)
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: Blue on July 05, 2011, 10:17:36 AM
Glad you like it ;)
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: amko_sa on July 05, 2011, 12:17:46 PM
When I activate recent php block, I have to many xhtml validation errors.
Can you correct that errors?
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: Blue on July 05, 2011, 04:23:32 PM
With scrolling off there isn't any XHTML errors but with scrolling ON there are because the <marquee> tag is not part of the XHTML specification, but most modern browsers support it.

To make it XHTML Valid the scrolling must be done with javascript but I don't know javascript. I might give it a try but no promises :(
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: amko_sa on July 05, 2011, 05:31:11 PM
Thank you blue :)
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: Blue on July 05, 2011, 09:29:04 PM
Ok, manage to get it up and running amko_sa ;)

There is a folder attached that you need to upload to your SMF's main directory in order to work.

And here is the code:
Code: [Select]
<?php

/*
Block: Recent posts with post preview [JavaScript Version]
Author: Blue @ Simple Portal.net
*/

/* [SETUP WHAT YOU WANT HERE] */

$topics_posts 2; // TOPICS - 1 | MESSAGES - 2
$limit 5; // How many recent posts do you want to output?
$number 70; // How many characters do you want to output?

// Scroll Enable? If you want to change the Height go to marquee.css | If speed go to marquee.js
$scrolling 1;       // ENABLE - 1 | DISABLE - 2

// Do you want to translate it to your own language? :P
$text['sportal_false'] = 'Simple Portal not found';
$text['board'] = 'in';
$text['who'] = 'by';

/* [STOP!] - THIS IS THE END OF SETUP */

//Only code from now on ;)
global $smcFunc$scripturl$sourcedir$modSettings;

// Lets see if you are using Simple Portal. If not...well...go get them :D
if (!file_exists($sourcedir '/PortalBlocks.php'))
{
echo $text['sportal_false'];
return;
}

// Let's grab some database results
if ($topics_posts == 1) {
$posts_result $smcFunc['db_query']('''
   SELECT m.poster_name, m.poster_time, m.id_msg, t.id_member_updated, m.subject, m.body, m.id_topic, b.name, t.id_last_msg, u.avatar, g.online_color
   FROM {db_prefix}topics AS t
   LEFT JOIN {db_prefix}boards AS b ON (t.id_board = b.id_board)
   LEFT JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_last_msg)
   LEFT JOIN {db_prefix}members AS u ON (t.id_member_updated = u.id_member)
   LEFT JOIN {db_prefix}membergroups AS g ON (g.id_group = CASE WHEN u.id_group = 0 THEN u.id_post_group ELSE u.id_group END)
   WHERE m.approved=1
   ORDER BY t.id_last_msg DESC
   LIMIT ' 
$limit);
$posts = array();
while (
$row_posts $smcFunc['db_fetch_assoc']($posts_result))
{

      global 
$memberContext;
      
loadMemberData($row_posts['id_member_updated']);
      
loadMemberContext($row_posts['id_member_updated']);

   
$posts[] = array(
  'id' => $row_posts['id_member_updated'],
      
'username' => '<a style="color: ' $row_posts['online_color'] . ';" href="' $scripturl '?action=profile;u=' $row_posts['id_member_updated'] . '">' $row_posts['poster_name'] . '</a>',
      
'subject' => '<a style="font-weight: bold;" title="' $text['board'] . '&nbsp;' $row_posts['name'] .'" href="' $scripturl '?topic=' $row_posts['id_topic'] . '.msg' $row_posts['id_last_msg'] . ';topicseen#new">' $row_posts['subject'] . '</a>',
      
'body' => $row_posts['body'],
  'avatar' => $row_posts['avatar'] == '' $memberContext[$row_posts['id_member_updated']]['avatar']['href'] : (stristr($row_posts['avatar'], 'http://') ? $row_posts['avatar'] : $modSettings['avatar_url'] . '/' $row_posts['avatar']),
  'board' => $row_posts['name'],
  'time' => timeformat($row_posts['poster_time'])
   );
}
$smcFunc['db_free_result']($posts_result);

} else {
$posts_result $smcFunc['db_query']('''
   SELECT m.poster_name, m.poster_time, m.id_msg, m.id_member, m.subject, m.body, m.id_topic, b.name, b.id_board, u.avatar, g.online_color
   FROM {db_prefix}messages AS m
   LEFT JOIN {db_prefix}boards AS b ON (m.id_board = b.id_board)
   LEFT JOIN {db_prefix}members AS u ON (m.id_member = u.id_member)
   LEFT JOIN {db_prefix}membergroups AS g ON (g.id_group = CASE WHEN u.id_group = 0 THEN u.id_post_group ELSE u.id_group END)   
   WHERE m.approved=1
   ORDER BY m.id_msg DESC
   LIMIT ' 
$limit);
$posts = array();
while (
$row_posts $smcFunc['db_fetch_assoc']($posts_result))
{

      global 
$memberContext;
      
loadMemberData($row_posts['id_member']);
      
loadMemberContext($row_posts['id_member']);

   
$posts[] = array(
  'id' => $row_posts['id_member'],
      
'username' => '<a style="color: ' $row_posts['online_color'] . ';" href="' $scripturl '?action=profile;u=' $row_posts['id_member'] . '">' $row_posts['poster_name'] . '</a>',
      
'subject' => '<a style="font-weight: bold;" title="' $text['board'] . '&nbsp;' $row_posts['name'] .'" href="' $scripturl '?topic=' $row_posts['id_topic'] . '.msg' $row_posts['id_msg'] . ';topicseen#new">' $row_posts['subject'] . '</a>',
      
'body' => $row_posts['body'],
  'avatar' => $row_posts['avatar'] == '' $memberContext[$row_posts['id_member']]['avatar']['href'] : (stristr($row_posts['avatar'], 'http://') ? $row_posts['avatar'] : $modSettings['avatar_url'] . '/' $row_posts['avatar']),
  'board' => $row_posts['name'],
  'idboard' => $row_posts['id_board'],   
  'time' => timeformat($row_posts['poster_time'])
   );
}
$smcFunc['db_free_result']($posts_result);

}

//Finally the Output

//Scrolling xD
if ($scrolling == 1) {
echo 
'
<script src="marquee/marquee.js" type="text/javascript"></script> 
<div style="width: auto; height:150px; overflow:hidden;" id="marquee_replacement" onmouseout="startit();" onmouseover="stop();">
<p style="height:150px;"></p>
'

}

foreach (
$posts as $post) {

if (
allowedTo('my_board_permission'$post['idboard'])) {

// Lets fix the BBCode bug and Strip the Text
$content1 str_replace("[""<"$post['body']);
$content2 str_replace("]"">"$content1); 
$content3 strip_tags($content2);
$preview substr ($content3,0,$number);

echo
'<table>
<tr>
<td style="width: 40px;">
<img src="' 
$post['avatar'] .'" alt="" width="40px" height="40px" />
</td>
<td>
$post['subject'] .'<br />
<small>' 
$text['who'] . '&nbsp;' $post['username'] . '&nbsp;|&nbsp;' $post['time'] .'</small>
</td>
</tr>
</table>
$preview .'...
<hr />'
;
}
}

//Scrolling xD
if ($scrolling == 1) {
echo 
'
<p style="height:150px;"></p>
</div>
'
;
}
?>
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: nob4uask on July 05, 2011, 10:14:00 PM
Arvo Blue,

This is off topic but thought I would see if you could take a look at an issue I am having.  You seem to be just a tad bit more knowledgable than myself. :applause:

The thread is http://simpleportal.net/index.php?topic=9176.msg48333#msg48333

One more thing.  How do you get the code in like a scrolling frame when you put it in a post ?

Thank You Sir.
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: Blue on July 05, 2011, 10:28:25 PM
Hi nob4uask,

Please don't create off-topics. If you need my help send me a PM and I will help you the best I can although, as you know, the best persons to help us all are Simple Portal team :D

There is a quick way to put things scrolling but it will cause an XHTML error since the <marquee> tag is not part of the XHTML specification, but most modern browsers support it. For the quick way you can use this tag:

Code: [Select]
<marquee behavior="scroll" direction="left">Your scrolling text goes here</marquee>see more here: http://www.quackit.com/html/codes/html_marquee_code.cfm (http://www.quackit.com/html/codes/html_marquee_code.cfm)

Only admins can use it in a post since they are the only ones that are allowed to use [ HTML ] bbcode.
Code: [Select]
[html]<marquee behavior="scroll" direction="left">Your scrolling text goes here</marquee>[/html]
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: Blue on July 24, 2011, 09:25:53 PM
Block updated. BBCode and Hidden Boards fix ;)
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: Old Fossil on July 24, 2011, 09:52:53 PM
Blue is there a way the avatars could be swapped for whatever the message icon is?

I don't want too many blocks showing a users avatar.

Looks very good though.
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: RaulVK on July 27, 2011, 10:01:31 PM
Block perfect, but .... Could you add the function that the image "new" appeared when we have not yet read that message? example:

(http://img225.imageshack.us/img225/3548/2807201135533.png)


(Sorry for my english)
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: Blue on July 31, 2011, 02:13:04 PM
It's done RaulVK.

Version 1.2 released.
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: Yngwiedis on July 31, 2011, 02:44:50 PM
Hello Blue...

Great block, but i have a small problem.
Some of the Greek characters are displayed like that:  �

Can you do something about that ?

Thank you very very much.

Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: Blue on July 31, 2011, 03:02:17 PM
Try this:

Code: [Select]
<?php

/*
Block: Recent posts with post preview
Author: Blue @ Simple Portal.net
*/

/* [SETUP WHAT YOU WANT HERE] */

$topics_posts 2; // TOPICS - 1 | MESSAGES - 2
$limit 5; // How many recent posts do you want to output?
$number 70; // How many characters do you want to output?

// Scroll Enable? Height and Speed?
$scrolling 1;       // ENABLE - 1 | DISABLE - 2
$height "150px";
$speed 3;           // SLOW - 1 | MEDIUM - 10 | FAST - 20

// Do you want to translate it to your own language? :P
$text['sportal_false'] = 'Simple Portal not found';
$text['board'] = 'in';
$text['who'] = 'by';

/* [STOP!] - THIS IS THE END OF SETUP */

//Only code from now on ;)
global $smcFunc$scripturl$sourcedir$modSettings$user_info$settings$context;

// Lets see if you are using Simple Portal. If not...well...go get them :D
if (!file_exists($sourcedir '/PortalBlocks.php'))
{
echo $text['sportal_false'];
return;
}

// Let's grab some database results
if ($topics_posts == 1) {
$posts_result $smcFunc['db_query']('''
   SELECT m.poster_name, m.poster_time, m.id_msg, t.id_member_updated, m.subject, m.body, m.id_topic, b.name, t.id_last_msg, u.avatar, g.online_color,' 
. ($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'
) . '
   FROM {db_prefix}topics AS t
   LEFT JOIN {db_prefix}boards AS b ON (t.id_board = b.id_board)
   LEFT JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_last_msg)
   LEFT JOIN {db_prefix}members AS u ON (t.id_member_updated = u.id_member)
   LEFT JOIN {db_prefix}membergroups AS g ON (g.id_group = CASE WHEN u.id_group = 0 THEN u.id_post_group ELSE u.id_group END)
   ' 
. (!$user_info['is_guest'] ? '
LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = m.id_topic AND lt.id_member = ' 
$user_info['id'] . ')
LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = b.id_board AND lmr.id_member = ' 
$user_info['id'] . ')' '') . '     
   WHERE m.approved=1
   ORDER BY t.id_last_msg DESC
   LIMIT ' 
$limit);
$posts = array();
while (
$row_posts $smcFunc['db_fetch_assoc']($posts_result))
{

      global 
$memberContext;
      
loadMemberData($row_posts['id_member_updated']);
      
loadMemberContext($row_posts['id_member_updated']);

   
$posts[] = array(
  'id' => $row_posts['id_member_updated'],
      
'username' => '<a style="color: ' $row_posts['online_color'] . ';" href="' $scripturl '?action=profile;u=' $row_posts['id_member_updated'] . '">' $row_posts['poster_name'] . '</a>',
      
'subject' => '<a style="font-weight: bold;" title="' $text['board'] . '&nbsp;' $row_posts['name'] .'" href="' $scripturl '?topic=' $row_posts['id_topic'] . '.msg' $row_posts['id_last_msg'] . ';topicseen#new">' $row_posts['subject'] . '</a>',
      
'body' => $row_posts['body'],
  'avatar' => $row_posts['avatar'] == '' $memberContext[$row_posts['id_member_updated']]['avatar']['href'] : (stristr($row_posts['avatar'], 'http://') ? $row_posts['avatar'] : $modSettings['avatar_url'] . '/' $row_posts['avatar']),
  'board' => $row_posts['name'],
  'time' => timeformat($row_posts['poster_time']),
  'new' => !empty($row_posts['is_read'])
   );
}
$smcFunc['db_free_result']($posts_result);

} else {
$posts_result $smcFunc['db_query']('''
   SELECT m.poster_name, m.poster_time, m.id_msg, m.id_member, m.subject, m.body, m.id_topic, b.name, b.id_board, u.avatar, g.online_color,' 
. ($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'
) . '
   FROM {db_prefix}messages AS m
   LEFT JOIN {db_prefix}boards AS b ON (m.id_board = b.id_board)
   LEFT JOIN {db_prefix}members AS u ON (m.id_member = u.id_member)
   LEFT JOIN {db_prefix}membergroups AS g ON (g.id_group = CASE WHEN u.id_group = 0 THEN u.id_post_group ELSE u.id_group END)
   ' 
. (!$user_info['is_guest'] ? '
LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = m.id_topic AND lt.id_member = ' 
$user_info['id'] . ')
LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = b.id_board AND lmr.id_member = ' 
$user_info['id'] . ')' '') . '   
   WHERE m.approved=1
   ORDER BY m.id_msg DESC
   LIMIT ' 
$limit);
$posts = array();
while (
$row_posts $smcFunc['db_fetch_assoc']($posts_result))
{

      global 
$memberContext;
      
loadMemberData($row_posts['id_member']);
      
loadMemberContext($row_posts['id_member']);

   
$posts[] = array(
  'id' => $row_posts['id_member'],
      
'username' => '<a style="color: ' $row_posts['online_color'] . ';" href="' $scripturl '?action=profile;u=' $row_posts['id_member'] . '">' $row_posts['poster_name'] . '</a>',
      
'subject' => '<a style="font-weight: bold;" title="' $text['board'] . '&nbsp;' $row_posts['name'] .'" href="' $scripturl '?topic=' $row_posts['id_topic'] . '.msg' $row_posts['id_msg'] . ';topicseen#new">' $row_posts['subject'] . '</a>',
      
'body' => $row_posts['body'],
  'avatar' => $row_posts['avatar'] == '' $memberContext[$row_posts['id_member']]['avatar']['href'] : (stristr($row_posts['avatar'], 'http://') ? $row_posts['avatar'] : $modSettings['avatar_url'] . '/' $row_posts['avatar']),
  'board' => $row_posts['name'],
  'idboard' => $row_posts['id_board'],   
  'time' => timeformat($row_posts['poster_time']),
  'new' => !empty($row_posts['is_read'])
   );
}
$smcFunc['db_free_result']($posts_result);

}

//Finally the Output

//Scrolling xD
if ($scrolling == 1)
echo 
'<marquee height=' $height ' behavior="scroll" direction="up" scrollamount="' $speed '" onmouseover="this.stop()" onmouseout="this.start()">';

foreach (
$posts as $post) {

// Lets fix the BBCode bug and Strip the Text
$content1 str_replace("[""<"$post['body']);
$content2 str_replace("]"">"$content1); 
$content3 strip_tags($content2);
$preview substr ($content3,0,$number);

echo
'<table>
<tr>
<td style="width: 40px;">
<img src="' 
$post['avatar'] .'" alt="" width="40px" height="40px" />
</td>
<td>
$post['subject'];

if (!$post['new'] && $context['user']['is_logged'])
echo '&nbsp;<img src="'$settings['images_url'], '/'$context['user']['language'], '/new.gif" alt="new" border="0" />';

echo '<br />
<small>' 
$text['who'] . '&nbsp;' $post['username'] . '&nbsp;|&nbsp;' $post['time'] .'</small>
</td>
</tr>
</table>
htmlspecialchars($previewENT_NOQUOTES"UTF-8") .'...
<hr />'
;
}

//Scrolling xD
if ($scrolling == 1)
echo 
'</marquee>';
?>
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: Yngwiedis on July 31, 2011, 06:02:59 PM
Now everything is ok :D

Thank you very very much.
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: RaulVK on July 31, 2011, 09:32:12 PM
only the administrator can see????
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: Blue on July 31, 2011, 09:34:18 PM
only the administrator can see????

Sorry, I had an error. Here, try this:
Code: [Select]
<?php

/*
Block: Recent posts with post preview
Author: Blue @ Simple Portal.net
Version: 1.2
*/

/* [SETUP WHAT YOU WANT HERE] */

$topics_posts 2; // TOPICS - 1 | MESSAGES - 2
$limit 5; // How many recent posts do you want to output?
$number 70; // How many characters do you want to output?

// Scroll Enable? Height and Speed?
$scrolling 1;       // ENABLE - 1 | DISABLE - 2
$height "150px";
$speed 3;           // SLOW - 1 | MEDIUM - 10 | FAST - 20

// Do you want to translate it to your own language? :P
$text['sportal_false'] = 'Simple Portal not found';
$text['board'] = 'in';
$text['who'] = 'by';

/* [STOP!] - THIS IS THE END OF SETUP */

//Only code from now on ;)
global $smcFunc$scripturl$sourcedir$modSettings$user_info$settings$context;

// Lets see if you are using Simple Portal. If not...well...go get them :D
if (!file_exists($sourcedir '/PortalBlocks.php'))
{
echo $text['sportal_false'];
return;
}

// Let's grab some database results
if ($topics_posts == 1) {
$posts_result $smcFunc['db_query']('''
   SELECT m.poster_name, m.poster_time, m.id_msg, t.id_member_updated, m.subject, m.body, m.id_topic, b.name, t.id_last_msg, u.avatar, g.online_color,' 
. ($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'
) . '
   FROM {db_prefix}topics AS t
   LEFT JOIN {db_prefix}boards AS b ON (t.id_board = b.id_board)
   LEFT JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_last_msg)
   LEFT JOIN {db_prefix}members AS u ON (t.id_member_updated = u.id_member)
   LEFT JOIN {db_prefix}membergroups AS g ON (g.id_group = CASE WHEN u.id_group = 0 THEN u.id_post_group ELSE u.id_group END)
   ' 
. (!$user_info['is_guest'] ? '
LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = m.id_topic AND lt.id_member = ' 
$user_info['id'] . ')
LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = b.id_board AND lmr.id_member = ' 
$user_info['id'] . ')' '') . '     
   WHERE m.approved=1
   ORDER BY t.id_last_msg DESC
   LIMIT ' 
$limit);
$posts = array();
while (
$row_posts $smcFunc['db_fetch_assoc']($posts_result))
{

      global 
$memberContext;
      
loadMemberData($row_posts['id_member_updated']);
      
loadMemberContext($row_posts['id_member_updated']);

   
$posts[] = array(
  'id' => $row_posts['id_member_updated'],
      
'username' => '<a style="color: ' $row_posts['online_color'] . ';" href="' $scripturl '?action=profile;u=' $row_posts['id_member_updated'] . '">' $row_posts['poster_name'] . '</a>',
      
'subject' => '<a style="font-weight: bold;" title="' $text['board'] . '&nbsp;' $row_posts['name'] .'" href="' $scripturl '?topic=' $row_posts['id_topic'] . '.msg' $row_posts['id_last_msg'] . ';topicseen#new">' $row_posts['subject'] . '</a>',
      
'body' => $row_posts['body'],
  'avatar' => $row_posts['avatar'] == '' $memberContext[$row_posts['id_member_updated']]['avatar']['href'] : (stristr($row_posts['avatar'], 'http://') ? $row_posts['avatar'] : $modSettings['avatar_url'] . '/' $row_posts['avatar']),
  'board' => $row_posts['name'],
  'idboard' => $row_posts['id_board'],   
  'time' => timeformat($row_posts['poster_time']),
  'new' => !empty($row_posts['is_read'])
   );
}
$smcFunc['db_free_result']($posts_result);

} else {
$posts_result $smcFunc['db_query']('''
   SELECT m.poster_name, m.poster_time, m.id_msg, m.id_member, m.subject, m.body, m.id_topic, b.name, b.id_board, u.avatar, g.online_color,' 
. ($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'
) . '
   FROM {db_prefix}messages AS m
   LEFT JOIN {db_prefix}boards AS b ON (m.id_board = b.id_board)
   LEFT JOIN {db_prefix}members AS u ON (m.id_member = u.id_member)
   LEFT JOIN {db_prefix}membergroups AS g ON (g.id_group = CASE WHEN u.id_group = 0 THEN u.id_post_group ELSE u.id_group END)
   ' 
. (!$user_info['is_guest'] ? '
LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = m.id_topic AND lt.id_member = ' 
$user_info['id'] . ')
LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = b.id_board AND lmr.id_member = ' 
$user_info['id'] . ')' '') . '   
   WHERE m.approved=1
   ORDER BY m.id_msg DESC
   LIMIT ' 
$limit);
$posts = array();
while (
$row_posts $smcFunc['db_fetch_assoc']($posts_result))
{

      global 
$memberContext;
      
loadMemberData($row_posts['id_member']);
      
loadMemberContext($row_posts['id_member']);

   
$posts[] = array(
  'id' => $row_posts['id_member'],
      
'username' => '<a style="color: ' $row_posts['online_color'] . ';" href="' $scripturl '?action=profile;u=' $row_posts['id_member'] . '">' $row_posts['poster_name'] . '</a>',
      
'subject' => '<a style="font-weight: bold;" title="' $text['board'] . '&nbsp;' $row_posts['name'] .'" href="' $scripturl '?topic=' $row_posts['id_topic'] . '.msg' $row_posts['id_msg'] . ';topicseen#new">' $row_posts['subject'] . '</a>',
      
'body' => $row_posts['body'],
  'avatar' => $row_posts['avatar'] == '' $memberContext[$row_posts['id_member']]['avatar']['href'] : (stristr($row_posts['avatar'], 'http://') ? $row_posts['avatar'] : $modSettings['avatar_url'] . '/' $row_posts['avatar']),
  'board' => $row_posts['name'],
  'idboard' => $row_posts['id_board'],   
  'time' => timeformat($row_posts['poster_time']),
  'new' => !empty($row_posts['is_read'])
   );
}
$smcFunc['db_free_result']($posts_result);

}

//Finally the Output

//Scrolling xD
if ($scrolling == 1)
echo 
'<marquee height=' $height ' behavior="scroll" direction="up" scrollamount="' $speed '" onmouseover="this.stop()" onmouseout="this.start()">';

foreach (
$posts as $post) {

// Lets fix the BBCode bug and Strip the Text
$content1 str_replace("[""<"$post['body']);
$content2 str_replace("]"">"$content1); 
$content3 strip_tags($content2);
$preview substr ($content3,0,$number);

echo
'<table>
<tr>
<td style="width: 40px;">
<img src="' 
$post['avatar'] .'" alt="" width="40px" height="40px" />
</td>
<td>
$post['subject'];

if (!$post['new'] && $context['user']['is_logged'])
echo '&nbsp;<img src="'$settings['images_url'], '/'$context['user']['language'], '/new.gif" alt="new" border="0" />';

echo '<br />
<small>' 
$text['who'] . '&nbsp;' $post['username'] . '&nbsp;|&nbsp;' $post['time'] .'</small>
</td>
</tr>
</table>
$preview .'...
<hr />'
;
}

//Scrolling xD
if ($scrolling == 1)
echo 
'</marquee>';
?>
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: Yngwiedis on August 07, 2011, 02:40:53 PM
Can you put the Greek characters fix in that too ?

Thank you very very much.
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: Blue on August 07, 2011, 03:18:26 PM
Here :)

Code: [Select]
<?php

/*
Block: Recent posts with post preview
Author: Blue @ Simple Portal.net
Version: 1.2
*/

/* [SETUP WHAT YOU WANT HERE] */

$topics_posts 2; // TOPICS - 1 | MESSAGES - 2
$limit 5; // How many recent posts do you want to output?
$number 70; // How many characters do you want to output?

// Scroll Enable? Height and Speed?
$scrolling 1;       // ENABLE - 1 | DISABLE - 2
$height "150px";
$speed 3;           // SLOW - 1 | MEDIUM - 10 | FAST - 20

// Do you want to translate it to your own language? :P
$text['sportal_false'] = 'Simple Portal not found';
$text['board'] = 'in';
$text['who'] = 'by';

/* [STOP!] - THIS IS THE END OF SETUP */

//Only code from now on ;)
global $smcFunc$scripturl$sourcedir$modSettings$user_info$settings$context;

// Lets see if you are using Simple Portal. If not...well...go get them :D
if (!file_exists($sourcedir '/PortalBlocks.php'))
{
echo $text['sportal_false'];
return;
}

// Let's grab some database results
if ($topics_posts == 1) {
$posts_result $smcFunc['db_query']('''
   SELECT m.poster_name, m.poster_time, m.id_msg, t.id_member_updated, m.subject, m.body, m.id_topic, b.name, t.id_last_msg, u.avatar, g.online_color,' 
. ($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'
) . '
   FROM {db_prefix}topics AS t
   LEFT JOIN {db_prefix}boards AS b ON (t.id_board = b.id_board)
   LEFT JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_last_msg)
   LEFT JOIN {db_prefix}members AS u ON (t.id_member_updated = u.id_member)
   LEFT JOIN {db_prefix}membergroups AS g ON (g.id_group = CASE WHEN u.id_group = 0 THEN u.id_post_group ELSE u.id_group END)
   ' 
. (!$user_info['is_guest'] ? '
LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = m.id_topic AND lt.id_member = ' 
$user_info['id'] . ')
LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = b.id_board AND lmr.id_member = ' 
$user_info['id'] . ')' '') . '     
   WHERE m.approved=1
   ORDER BY t.id_last_msg DESC
   LIMIT ' 
$limit);
$posts = array();
while (
$row_posts $smcFunc['db_fetch_assoc']($posts_result))
{

      global 
$memberContext;
      
loadMemberData($row_posts['id_member_updated']);
      
loadMemberContext($row_posts['id_member_updated']);

   
$posts[] = array(
  'id' => $row_posts['id_member_updated'],
      
'username' => '<a style="color: ' $row_posts['online_color'] . ';" href="' $scripturl '?action=profile;u=' $row_posts['id_member_updated'] . '">' $row_posts['poster_name'] . '</a>',
      
'subject' => '<a style="font-weight: bold;" title="' $text['board'] . '&nbsp;' $row_posts['name'] .'" href="' $scripturl '?topic=' $row_posts['id_topic'] . '.msg' $row_posts['id_last_msg'] . ';topicseen#new">' $row_posts['subject'] . '</a>',
      
'body' => $row_posts['body'],
  'avatar' => $row_posts['avatar'] == '' $memberContext[$row_posts['id_member_updated']]['avatar']['href'] : (stristr($row_posts['avatar'], 'http://') ? $row_posts['avatar'] : $modSettings['avatar_url'] . '/' $row_posts['avatar']),
  'board' => $row_posts['name'],
  'idboard' => $row_posts['id_board'],   
  'time' => timeformat($row_posts['poster_time']),
  'new' => !empty($row_posts['is_read'])
   );
}
$smcFunc['db_free_result']($posts_result);

} else {
$posts_result $smcFunc['db_query']('''
   SELECT m.poster_name, m.poster_time, m.id_msg, m.id_member, m.subject, m.body, m.id_topic, b.name, b.id_board, u.avatar, g.online_color,' 
. ($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'
) . '
   FROM {db_prefix}messages AS m
   LEFT JOIN {db_prefix}boards AS b ON (m.id_board = b.id_board)
   LEFT JOIN {db_prefix}members AS u ON (m.id_member = u.id_member)
   LEFT JOIN {db_prefix}membergroups AS g ON (g.id_group = CASE WHEN u.id_group = 0 THEN u.id_post_group ELSE u.id_group END)
   ' 
. (!$user_info['is_guest'] ? '
LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = m.id_topic AND lt.id_member = ' 
$user_info['id'] . ')
LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = b.id_board AND lmr.id_member = ' 
$user_info['id'] . ')' '') . '   
   WHERE m.approved=1
   ORDER BY m.id_msg DESC
   LIMIT ' 
$limit);
$posts = array();
while (
$row_posts $smcFunc['db_fetch_assoc']($posts_result))
{

      global 
$memberContext;
      
loadMemberData($row_posts['id_member']);
      
loadMemberContext($row_posts['id_member']);

   
$posts[] = array(
  'id' => $row_posts['id_member'],
      
'username' => '<a style="color: ' $row_posts['online_color'] . ';" href="' $scripturl '?action=profile;u=' $row_posts['id_member'] . '">' $row_posts['poster_name'] . '</a>',
      
'subject' => '<a style="font-weight: bold;" title="' $text['board'] . '&nbsp;' $row_posts['name'] .'" href="' $scripturl '?topic=' $row_posts['id_topic'] . '.msg' $row_posts['id_msg'] . ';topicseen#new">' $row_posts['subject'] . '</a>',
      
'body' => $row_posts['body'],
  'avatar' => $row_posts['avatar'] == '' $memberContext[$row_posts['id_member']]['avatar']['href'] : (stristr($row_posts['avatar'], 'http://') ? $row_posts['avatar'] : $modSettings['avatar_url'] . '/' $row_posts['avatar']),
  'board' => $row_posts['name'],
  'idboard' => $row_posts['id_board'],   
  'time' => timeformat($row_posts['poster_time']),
  'new' => !empty($row_posts['is_read'])
   );
}
$smcFunc['db_free_result']($posts_result);

}

//Finally the Output

//Scrolling xD
if ($scrolling == 1)
echo 
'<marquee height=' $height ' behavior="scroll" direction="up" scrollamount="' $speed '" onmouseover="this.stop()" onmouseout="this.start()">';

foreach (
$posts as $post) {

// Lets fix the BBCode bug and Strip the Text
$content1 str_replace("[""<"$post['body']);
$content2 str_replace("]"">"$content1); 
$content3 strip_tags($content2);
$preview substr ($content3,0,$number);

echo
'<table>
<tr>
<td style="width: 40px;">
<img src="' 
$post['avatar'] .'" alt="" width="40px" height="40px" />
</td>
<td>
$post['subject'];

if (!$post['new'] && $context['user']['is_logged'])
echo '&nbsp;<img src="'$settings['images_url'], '/'$context['user']['language'], '/new.gif" alt="new" border="0" />';

echo '<br />
<small>' 
$text['who'] . '&nbsp;' $post['username'] . '&nbsp;|&nbsp;' $post['time'] .'</small>
</td>
</tr>
</table>
htmlspecialchars($previewENT_NOQUOTES"UTF-8") .'...
<hr />'
;
}

//Scrolling xD
if ($scrolling == 1)
echo 
'</marquee>';
?>
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: Yngwiedis on August 08, 2011, 02:19:07 AM
Hello again Blue...

I have the block visible to guests, but i don't want to be able to see latest posts from boards that are not accessible for them.
Can you do something about that ?

Also in the preview of posts, spaces characters are not displaying correct.

Thank you very very much.
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: RaulVK on August 08, 2011, 08:56:56 AM
Yes. You see the messages of the sections that do not have permission. It happens with all membergroups.
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: Blue on August 10, 2011, 03:58:38 PM
I have the block visible to guests, but i don't want to be able to see latest posts from boards that are not accessible for them.

I'm gonna fix it as soon as I can.
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: Christopher on August 10, 2011, 11:12:08 PM
I have the block visible to guests, but i don't want to be able to see latest posts from boards that are not accessible for them.

I'm gonna fix it as soon as I can.

I didn't know that this would happen and I used this and now all of my members saw a bunch of private content that they shouldn't of seen.  :whistle:
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: Christopher on September 01, 2011, 01:31:46 AM
Will there be an update for this?
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: Blue on September 01, 2011, 05:33:11 PM
Yes, it will. It has been a busy week. Next week I'll fix it ;)
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: Blue on September 07, 2011, 08:02:42 PM
Block Upgraded! Version 1.3 -> Permissions Fix! (exclude boards that you want to hide from guests)

SEE THE SETUP

Code: [Select]
<?php

/*
Block: Recent posts with post preview
Author: Blue @ Simple Portal.net
Version: 1.3
*/

/* [SETUP WHAT YOU WANT HERE] */

$topics_posts 1; // TOPICS - 1 | MESSAGES - 2
$limit 5; // How many recent posts do you want to output?
$number 70; // How many characters do you want to output?
$exclude_boards null; // IF null guests can see all boards | IF you want to hide some boards use: array( ID1, ID2, ID3) where ID is the board's ID

// Scroll Enable? Height and Speed?
$scrolling 1;       // ENABLE - 1 | DISABLE - 2
$height "150px";
$speed 3;           // SLOW - 1 | MEDIUM - 10 | FAST - 20

// Do you want to translate it to your own language? :P
$text['sportal_false'] = 'Simple Portal not found';
$text['board'] = 'in';
$text['who'] = 'by';

/* [STOP!] - THIS IS THE END OF SETUP */

//Only code from now on ;)
global $smcFunc$scripturl$sourcedir$modSettings$user_info$settings$context;

// Lets see if you are using Simple Portal. If not...well...go get them :D
if (!file_exists($sourcedir '/PortalBlocks.php'))
{
echo $text['sportal_false'];
return;
}

// Let's grab some database results
if ($topics_posts == 1) {

if (is_array($exclude_boards) || (int) $exclude_boards === $exclude_boards)
{
$exclude_boards is_array($exclude_boards) ? $exclude_boards : array($exclude_boards);
}
elseif ($exclude_boards != null)
{
$output_method $exclude_boards;
$exclude_boards = array();
}

$posts_result $smcFunc['db_query']('''
   SELECT m.poster_name, m.poster_time, m.id_msg, t.id_member_updated, m.subject, m.body, m.id_topic, b.name, t.id_last_msg, u.avatar, g.online_color,' 
. ($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'
) . '
   FROM {db_prefix}topics AS t
   LEFT JOIN {db_prefix}boards AS b ON (t.id_board = b.id_board)
   LEFT JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_last_msg)
   LEFT JOIN {db_prefix}members AS u ON (t.id_member_updated = u.id_member)
   LEFT JOIN {db_prefix}membergroups AS g ON (g.id_group = CASE WHEN u.id_group = 0 THEN u.id_post_group ELSE u.id_group END)
   ' 
. (!$user_info['is_guest'] ? '
LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = m.id_topic AND lt.id_member = ' 
$user_info['id'] . ')
LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = b.id_board AND lmr.id_member = ' 
$user_info['id'] . ')' '') . '     
   WHERE m.approved=1'   
. (empty($exclude_boards) ? '' : (!$user_info['is_guest'] ? '' '
AND b.id_board NOT IN ({array_int:exclude_boards})'
)) . '
   ORDER BY t.id_last_msg DESC
   LIMIT ' 
$limit
array(
'exclude_boards' => empty($exclude_boards) ? '' $exclude_boards,
)   
   );
$posts = array();
while (
$row_posts $smcFunc['db_fetch_assoc']($posts_result))
{

      global 
$memberContext;
      
loadMemberData($row_posts['id_member_updated']);
      
loadMemberContext($row_posts['id_member_updated']);

   
$posts[] = array(
  'id' => $row_posts['id_member_updated'],
      
'username' => '<a style="color: ' $row_posts['online_color'] . ';" href="' $scripturl '?action=profile;u=' $row_posts['id_member_updated'] . '">' $row_posts['poster_name'] . '</a>',
      
'subject' => '<a style="font-weight: bold;" title="' $text['board'] . '&nbsp;' $row_posts['name'] .'" href="' $scripturl '?topic=' $row_posts['id_topic'] . '.msg' $row_posts['id_last_msg'] . ';topicseen#new">' $row_posts['subject'] . '</a>',
      
'body' => $row_posts['body'],
  'avatar' => $row_posts['avatar'] == '' $memberContext[$row_posts['id_member_updated']]['avatar']['href'] : (stristr($row_posts['avatar'], 'http://') ? $row_posts['avatar'] : $modSettings['avatar_url'] . '/' $row_posts['avatar']),
  'board' => $row_posts['name'],
  'idboard' => $row_posts['id_board'],   
  'time' => timeformat($row_posts['poster_time']),
  'new' => !empty($row_posts['is_read'])
   );
}
$smcFunc['db_free_result']($posts_result);

} else {

if (is_array($exclude_boards) || (int) $exclude_boards === $exclude_boards)
{
$exclude_boards is_array($exclude_boards) ? $exclude_boards : array($exclude_boards);
}
elseif ($exclude_boards != null)
{
$output_method $exclude_boards;
$exclude_boards = array();
}

$posts_result $smcFunc['db_query']('''
   SELECT m.poster_name, m.poster_time, m.id_msg, m.id_member, m.subject, m.body, m.id_topic, b.name, b.id_board, u.avatar, g.online_color,' 
. ($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'
) . '
   FROM {db_prefix}messages AS m
   LEFT JOIN {db_prefix}boards AS b ON (m.id_board = b.id_board)
   LEFT JOIN {db_prefix}members AS u ON (m.id_member = u.id_member)
   LEFT JOIN {db_prefix}membergroups AS g ON (g.id_group = CASE WHEN u.id_group = 0 THEN u.id_post_group ELSE u.id_group END)
   ' 
. (!$user_info['is_guest'] ? '
LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = m.id_topic AND lt.id_member = ' 
$user_info['id'] . ')
LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = b.id_board AND lmr.id_member = ' 
$user_info['id'] . ')' '') . '   
   WHERE m.approved=1
   ORDER BY m.id_msg DESC
   LIMIT ' 
$limit);
$posts = array();
while (
$row_posts $smcFunc['db_fetch_assoc']($posts_result))
{

      global 
$memberContext;
      
loadMemberData($row_posts['id_member']);
      
loadMemberContext($row_posts['id_member']);

   
$posts[] = array(
  'id' => $row_posts['id_member'],
      
'username' => '<a style="color: ' $row_posts['online_color'] . ';" href="' $scripturl '?action=profile;u=' $row_posts['id_member'] . '">' $row_posts['poster_name'] . '</a>',
      
'subject' => '<a style="font-weight: bold;" title="' $text['board'] . '&nbsp;' $row_posts['name'] .'" href="' $scripturl '?topic=' $row_posts['id_topic'] . '.msg' $row_posts['id_msg'] . ';topicseen#new">' $row_posts['subject'] . '</a>',
      
'body' => $row_posts['body'],
  'avatar' => $row_posts['avatar'] == '' $memberContext[$row_posts['id_member']]['avatar']['href'] : (stristr($row_posts['avatar'], 'http://') ? $row_posts['avatar'] : $modSettings['avatar_url'] . '/' $row_posts['avatar']),
  'board' => $row_posts['name'],
  'idboard' => $row_posts['id_board'],   
  'time' => timeformat($row_posts['poster_time']),
  'new' => !empty($row_posts['is_read'])
   );
}
$smcFunc['db_free_result']($posts_result);

}

//Finally the Output

//Scrolling xD
if ($scrolling == 1)
echo 
'<marquee height=' $height ' behavior="scroll" direction="up" scrollamount="' $speed '" onmouseover="this.stop()" onmouseout="this.start()">';

foreach (
$posts as $post) {

// Lets fix the BBCode bug and Strip the Text
$content1 str_replace("[""<"$post['body']);
$content2 str_replace("]"">"$content1); 
$content3 strip_tags($content2);
$preview substr ($content3,0,$number);

echo
'<table>
<tr>
<td style="width: 40px;">
<img src="' 
$post['avatar'] .'" alt="" width="40px" height="40px" />
</td>
<td>
$post['subject'];

if (!$post['new'] && $context['user']['is_logged'])
echo '&nbsp;<img src="'$settings['images_url'], '/'$context['user']['language'], '/new.gif" alt="new" border="0" />';

echo '<br />
<small>' 
$text['who'] . '&nbsp;' $post['username'] . '&nbsp;|&nbsp;' $post['time'] .'</small>
</td>
</tr>
</table>
htmlspecialchars($previewENT_NOQUOTES"UTF-8") .'...
<hr />'
;
}

//Scrolling xD
if ($scrolling == 1)
echo 
'</marquee>';
?>
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: Old Fossil on September 07, 2011, 08:28:43 PM
Bet ya worn out already  :nervous-happy:
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: Blue on September 07, 2011, 08:53:01 PM
Coding does not worn me out ;) (too much ahah)
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: David on September 08, 2011, 10:38:08 PM
Block Upgraded! Version 1.3 -> Permissions Fix! (exclude boards that you want to hide from guests)


Hey Blue!  Dude...this is awesome stuff!  I do have ONE question, however...

In Internet Explorer (HISSSSSSSSS!!) the code works fine but there's an ugly scroll bar on the right of the block.  Is there anything I can do about that?  The block is just too cool, even with the scroll bar, so I'll use it regardless...but I would like to remove that bar, if possible.  It's great in all the other browsers.

Thanks,

David
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: [SiNaN] on September 09, 2011, 03:40:07 AM
Can you get us a screenshot of the problem?
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: Blue on September 09, 2011, 01:02:00 PM
You should upgrade internet explorer 8 ;)

Here it is the fix:
Code: [Select]
<?php

/*
Block: Recent posts with post preview
Author: Blue @ Simple Portal.net
Version: 1.4
*/

/* [SETUP WHAT YOU WANT HERE] */

$topics_posts 1; // TOPICS - 1 | MESSAGES - 2
$limit 5; // How many recent posts do you want to output?
$number 70; // How many characters do you want to output?
$exclude_boards null; // IF null guests can see all boards | IF you want to hide some boards use: array( ID1, ID2, ID3) where ID is the board's ID

// Scroll Enable? Height and Speed?
$scrolling 1;       // ENABLE - 1 | DISABLE - 2
$height "150px";
$speed 3;           // SLOW - 1 | MEDIUM - 10 | FAST - 20

// Do you want to translate it to your own language? :P
$text['sportal_false'] = 'Simple Portal not found';
$text['board'] = 'in';
$text['who'] = 'by';

/* [STOP!] - THIS IS THE END OF SETUP */

//Only code from now on ;)
global $smcFunc$scripturl$sourcedir$modSettings$user_info$settings$context;

// Lets see if you are using Simple Portal. If not...well...go get them :D
if (!file_exists($sourcedir '/PortalBlocks.php'))
{
echo $text['sportal_false'];
return;
}

// Let's grab some database results
if ($topics_posts == 1) {

if (is_array($exclude_boards) || (int) $exclude_boards === $exclude_boards)
{
$exclude_boards is_array($exclude_boards) ? $exclude_boards : array($exclude_boards);
}
elseif ($exclude_boards != null)
{
$output_method $exclude_boards;
$exclude_boards = array();
}

$posts_result $smcFunc['db_query']('''
   SELECT m.poster_name, m.poster_time, m.id_msg, t.id_member_updated, m.subject, m.body, m.id_topic, b.name, t.id_last_msg, u.avatar, g.online_color,' 
. ($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'
) . '
   FROM {db_prefix}topics AS t
   LEFT JOIN {db_prefix}boards AS b ON (t.id_board = b.id_board)
   LEFT JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_last_msg)
   LEFT JOIN {db_prefix}members AS u ON (t.id_member_updated = u.id_member)
   LEFT JOIN {db_prefix}membergroups AS g ON (g.id_group = CASE WHEN u.id_group = 0 THEN u.id_post_group ELSE u.id_group END)
   ' 
. (!$user_info['is_guest'] ? '
LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = m.id_topic AND lt.id_member = ' 
$user_info['id'] . ')
LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = b.id_board AND lmr.id_member = ' 
$user_info['id'] . ')' '') . '     
   WHERE m.approved=1'   
. (empty($exclude_boards) ? '' : (!$user_info['is_guest'] ? '' '
AND b.id_board NOT IN ({array_int:exclude_boards})'
)) . '
   ORDER BY t.id_last_msg DESC
   LIMIT ' 
$limit
array(
'exclude_boards' => empty($exclude_boards) ? '' $exclude_boards,
)   
   );
$posts = array();
while (
$row_posts $smcFunc['db_fetch_assoc']($posts_result))
{

      global 
$memberContext;
      
loadMemberData($row_posts['id_member_updated']);
      
loadMemberContext($row_posts['id_member_updated']);

   
$posts[] = array(
  'id' => $row_posts['id_member_updated'],
      
'username' => '<a style="color: ' $row_posts['online_color'] . ';" href="' $scripturl '?action=profile;u=' $row_posts['id_member_updated'] . '">' $row_posts['poster_name'] . '</a>',
      
'subject' => '<a style="font-weight: bold;" title="' $text['board'] . '&nbsp;' $row_posts['name'] .'" href="' $scripturl '?topic=' $row_posts['id_topic'] . '.msg' $row_posts['id_last_msg'] . ';topicseen#new">' $row_posts['subject'] . '</a>',
      
'body' => $row_posts['body'],
  'avatar' => $row_posts['avatar'] == '' $memberContext[$row_posts['id_member_updated']]['avatar']['href'] : (stristr($row_posts['avatar'], 'http://') ? $row_posts['avatar'] : $modSettings['avatar_url'] . '/' $row_posts['avatar']),
  'board' => $row_posts['name'],
  'idboard' => $row_posts['id_board'],   
  'time' => timeformat($row_posts['poster_time']),
  'new' => !empty($row_posts['is_read'])
   );
}
$smcFunc['db_free_result']($posts_result);

} else {

if (is_array($exclude_boards) || (int) $exclude_boards === $exclude_boards)
{
$exclude_boards is_array($exclude_boards) ? $exclude_boards : array($exclude_boards);
}
elseif ($exclude_boards != null)
{
$output_method $exclude_boards;
$exclude_boards = array();
}

$posts_result $smcFunc['db_query']('''
   SELECT m.poster_name, m.poster_time, m.id_msg, m.id_member, m.subject, m.body, m.id_topic, b.name, b.id_board, u.avatar, g.online_color,' 
. ($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'
) . '
   FROM {db_prefix}messages AS m
   LEFT JOIN {db_prefix}boards AS b ON (m.id_board = b.id_board)
   LEFT JOIN {db_prefix}members AS u ON (m.id_member = u.id_member)
   LEFT JOIN {db_prefix}membergroups AS g ON (g.id_group = CASE WHEN u.id_group = 0 THEN u.id_post_group ELSE u.id_group END)
   ' 
. (!$user_info['is_guest'] ? '
LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = m.id_topic AND lt.id_member = ' 
$user_info['id'] . ')
LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = b.id_board AND lmr.id_member = ' 
$user_info['id'] . ')' '') . '   
   WHERE m.approved=1
   ORDER BY m.id_msg DESC
   LIMIT ' 
$limit);
$posts = array();
while (
$row_posts $smcFunc['db_fetch_assoc']($posts_result))
{

      global 
$memberContext;
      
loadMemberData($row_posts['id_member']);
      
loadMemberContext($row_posts['id_member']);

   
$posts[] = array(
  'id' => $row_posts['id_member'],
      
'username' => '<a style="color: ' $row_posts['online_color'] . ';" href="' $scripturl '?action=profile;u=' $row_posts['id_member'] . '">' $row_posts['poster_name'] . '</a>',
      
'subject' => '<a style="font-weight: bold;" title="' $text['board'] . '&nbsp;' $row_posts['name'] .'" href="' $scripturl '?topic=' $row_posts['id_topic'] . '.msg' $row_posts['id_msg'] . ';topicseen#new">' $row_posts['subject'] . '</a>',
      
'body' => $row_posts['body'],
  'avatar' => $row_posts['avatar'] == '' $memberContext[$row_posts['id_member']]['avatar']['href'] : (stristr($row_posts['avatar'], 'http://') ? $row_posts['avatar'] : $modSettings['avatar_url'] . '/' $row_posts['avatar']),
  'board' => $row_posts['name'],
  'idboard' => $row_posts['id_board'],   
  'time' => timeformat($row_posts['poster_time']),
  'new' => !empty($row_posts['is_read'])
   );
}
$smcFunc['db_free_result']($posts_result);

}

//Finally the Output

//Scrolling xD
if ($scrolling == 1)
echo 
'<div style="overflow: hidden;"><marquee height=' $height ' behavior="scroll" direction="up" scrollamount="' $speed '" onmouseover="this.stop()" onmouseout="this.start()">';

foreach (
$posts as $post) {

// Lets fix the BBCode bug and Strip the Text
$content1 str_replace("[""<"$post['body']);
$content2 str_replace("]"">"$content1); 
$content3 strip_tags($content2);
$preview substr ($content3,0,$number);

echo
'<table>
<tr>
<td style="width: 40px;">
<img src="' 
$post['avatar'] .'" alt="" width="40px" height="40px" />
</td>
<td>
$post['subject'];

if (!$post['new'] && $context['user']['is_logged'])
echo '&nbsp;<img src="'$settings['images_url'], '/'$context['user']['language'], '/new.gif" alt="new" border="0" />';

echo '<br />
<small>' 
$text['who'] . '&nbsp;' $post['username'] . '&nbsp;|&nbsp;' $post['time'] .'</small>
</td>
</tr>
</table>
htmlspecialchars($previewENT_NOQUOTES"UTF-8") .'...
<hr />'
;
}

//Scrolling xD
if ($scrolling == 1)
echo 
'</marquee></div>';
?>
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: MaXi on September 09, 2011, 02:37:38 PM
Nice man :-)
But when user haven´t avatar, is there blank place.
Is it possible add fix for example: http://media.simplemachinesweb.com/smf/default/images/icons/online.gif ?
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: David on September 09, 2011, 05:32:20 PM
Quote
You should upgrade internet explorer 8 ;)

I'm already on Explorer 8.  Could care less about it, frankly.  I prefer Firefox or....well...ANYTHING but IE.  I was just more or less concerned for my members who have to see the scrolly bars.  But hey, thanks for the fix!  You're a guru, dude!! Much appreciated.


Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: Blue on September 09, 2011, 10:30:27 PM
Nice man :-)
But when user haven´t avatar, is there blank place.
Is it possible add fix for example: http://media.simplemachinesweb.com/smf/default/images/icons/online.gif ?

Try this. Dont forget to change the image in the SETUP bellow :)

Code: [Select]
<?php

/*
Block: Recent posts with post preview
Author: Blue @ Simple Portal.net
Version: 1.4
*/

/* [SETUP WHAT YOU WANT HERE] */

$topics_posts 1; // TOPICS - 1 | MESSAGES - 2
$limit 5; // How many recent posts do you want to output?
$number 70; // How many characters do you want to output?
$exclude_boards null; // IF null guests can see all boards | IF you want to hide some boards use: array( ID1, ID2, ID3) where ID is the board's ID
$default_avatar 'http://thumb7.shutterstock.com/photos/thumb_large/57456/57456,1204703264,8.jpg';

// Scroll Enable? Height and Speed?
$scrolling 1;       // ENABLE - 1 | DISABLE - 2
$height "150px";
$speed 3;           // SLOW - 1 | MEDIUM - 10 | FAST - 20

// Do you want to translate it to your own language? :P
$text['sportal_false'] = 'Simple Portal not found';
$text['board'] = 'in';
$text['who'] = 'by';

/* [STOP!] - THIS IS THE END OF SETUP */

//Only code from now on ;)
global $smcFunc$scripturl$sourcedir$modSettings$user_info$settings$context;

// Lets see if you are using Simple Portal. If not...well...go get them :D
if (!file_exists($sourcedir '/PortalBlocks.php'))
{
echo $text['sportal_false'];
return;
}

// Let's grab some database results
if ($topics_posts == 1) {

if (is_array($exclude_boards) || (int) $exclude_boards === $exclude_boards)
{
$exclude_boards is_array($exclude_boards) ? $exclude_boards : array($exclude_boards);
}
elseif ($exclude_boards != null)
{
$output_method $exclude_boards;
$exclude_boards = array();
}

$posts_result $smcFunc['db_query']('''
   SELECT m.poster_name, m.poster_time, m.id_msg, t.id_member_updated, m.subject, m.body, m.id_topic, b.name, t.id_last_msg, u.avatar, g.online_color,' 
. ($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'
) . '
   FROM {db_prefix}topics AS t
   LEFT JOIN {db_prefix}boards AS b ON (t.id_board = b.id_board)
   LEFT JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_last_msg)
   LEFT JOIN {db_prefix}members AS u ON (t.id_member_updated = u.id_member)
   LEFT JOIN {db_prefix}membergroups AS g ON (g.id_group = CASE WHEN u.id_group = 0 THEN u.id_post_group ELSE u.id_group END)
   ' 
. (!$user_info['is_guest'] ? '
LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = m.id_topic AND lt.id_member = ' 
$user_info['id'] . ')
LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = b.id_board AND lmr.id_member = ' 
$user_info['id'] . ')' '') . '     
   WHERE m.approved=1'   
. (empty($exclude_boards) ? '' : (!$user_info['is_guest'] ? '' '
AND b.id_board NOT IN ({array_int:exclude_boards})'
)) . '
   ORDER BY t.id_last_msg DESC
   LIMIT ' 
$limit
array(
'exclude_boards' => empty($exclude_boards) ? '' $exclude_boards,
)   
   );
$posts = array();
while (
$row_posts $smcFunc['db_fetch_assoc']($posts_result))
{

      global 
$memberContext;
      
loadMemberData($row_posts['id_member_updated']);
      
loadMemberContext($row_posts['id_member_updated']);

   
$posts[] = array(
  'id' => $row_posts['id_member_updated'],
      
'username' => '<a style="color: ' $row_posts['online_color'] . ';" href="' $scripturl '?action=profile;u=' $row_posts['id_member_updated'] . '">' $row_posts['poster_name'] . '</a>',
      
'subject' => '<a style="font-weight: bold;" title="' $text['board'] . '&nbsp;' $row_posts['name'] .'" href="' $scripturl '?topic=' $row_posts['id_topic'] . '.msg' $row_posts['id_last_msg'] . ';topicseen#new">' $row_posts['subject'] . '</a>',
      
'body' => $row_posts['body'],
  'avatar' => $row_posts['avatar'] == '' $memberContext[$row_posts['id_member_updated']]['avatar']['href'] : (stristr($row_posts['avatar'], 'http://') ? $row_posts['avatar'] : $modSettings['avatar_url'] . '/' $row_posts['avatar']),
  'board' => $row_posts['name'],
  'idboard' => $row_posts['id_board'],   
  'time' => timeformat($row_posts['poster_time']),
  'new' => !empty($row_posts['is_read'])
   );
}
$smcFunc['db_free_result']($posts_result);

} else {

if (is_array($exclude_boards) || (int) $exclude_boards === $exclude_boards)
{
$exclude_boards is_array($exclude_boards) ? $exclude_boards : array($exclude_boards);
}
elseif ($exclude_boards != null)
{
$output_method $exclude_boards;
$exclude_boards = array();
}

$posts_result $smcFunc['db_query']('''
   SELECT m.poster_name, m.poster_time, m.id_msg, m.id_member, m.subject, m.body, m.id_topic, b.name, b.id_board, u.avatar, g.online_color,' 
. ($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'
) . '
   FROM {db_prefix}messages AS m
   LEFT JOIN {db_prefix}boards AS b ON (m.id_board = b.id_board)
   LEFT JOIN {db_prefix}members AS u ON (m.id_member = u.id_member)
   LEFT JOIN {db_prefix}membergroups AS g ON (g.id_group = CASE WHEN u.id_group = 0 THEN u.id_post_group ELSE u.id_group END)
   ' 
. (!$user_info['is_guest'] ? '
LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = m.id_topic AND lt.id_member = ' 
$user_info['id'] . ')
LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = b.id_board AND lmr.id_member = ' 
$user_info['id'] . ')' '') . '   
   WHERE m.approved=1
   ORDER BY m.id_msg DESC
   LIMIT ' 
$limit);
$posts = array();
while (
$row_posts $smcFunc['db_fetch_assoc']($posts_result))
{

      global 
$memberContext;
      
loadMemberData($row_posts['id_member']);
      
loadMemberContext($row_posts['id_member']);

   
$posts[] = array(
  'id' => $row_posts['id_member'],
      
'username' => '<a style="color: ' $row_posts['online_color'] . ';" href="' $scripturl '?action=profile;u=' $row_posts['id_member'] . '">' $row_posts['poster_name'] . '</a>',
      
'subject' => '<a style="font-weight: bold;" title="' $text['board'] . '&nbsp;' $row_posts['name'] .'" href="' $scripturl '?topic=' $row_posts['id_topic'] . '.msg' $row_posts['id_msg'] . ';topicseen#new">' $row_posts['subject'] . '</a>',
      
'body' => $row_posts['body'],
  'avatar' => $row_posts['avatar'] == '' $memberContext[$row_posts['id_member']]['avatar']['href'] : (stristr($row_posts['avatar'], 'http://') ? $row_posts['avatar'] : $modSettings['avatar_url'] . '/' $row_posts['avatar']),
  'board' => $row_posts['name'],
  'idboard' => $row_posts['id_board'],   
  'time' => timeformat($row_posts['poster_time']),
  'new' => !empty($row_posts['is_read'])
   );
}
$smcFunc['db_free_result']($posts_result);

}

//Finally the Output

//Scrolling xD
if ($scrolling == 1)
echo 
'<div style="overflow: hidden;"><marquee height=' $height ' behavior="scroll" direction="up" scrollamount="' $speed '" onmouseover="this.stop()" onmouseout="this.start()">';

foreach (
$posts as $post) {

// Lets fix the BBCode bug and Strip the Text
$content1 str_replace("[""<"$post['body']);
$content2 str_replace("]"">"$content1); 
$content3 strip_tags($content2);
$preview substr ($content3,0,$number);

echo
'<table>
<tr>
<td style="width: 40px;">'
;

if (!empty($post['avatar'])){
echo '<img src="' $post['avatar'] .'" alt="" width="40px" height="40px" />';
} else {
echo '<img src="' $default_avatar .'" alt="" width="40px" height="40px" />';
}

echo 
'</td>
<td>
$post['subject'];

if (!$post['new'] && $context['user']['is_logged'])
echo '&nbsp;<img src="'$settings['images_url'], '/'$context['user']['language'], '/new.gif" alt="new" border="0" />';

echo '<br />
<small>' 
$text['who'] . '&nbsp;' $post['username'] . '&nbsp;|&nbsp;' $post['time'] .'</small>
</td>
</tr>
</table>
htmlspecialchars($previewENT_NOQUOTES"UTF-8") .'...
<hr />'
;
}

//Scrolling xD
if ($scrolling == 1)
echo 
'</marquee></div>';
?>

I'm already on Explorer 8.
I meant that you should upgrade IE8 to IE9 :P
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: MaXi on September 10, 2011, 02:47:05 PM
Very nice man! ;)
Thank you
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: Mick. on September 14, 2011, 12:44:48 PM
Very cool Blue.

Couple things, I modified to suit my needs, http://www.bluedevilcustoms.com/community/index.php (right block) but im stumped on two details.

1. I don't want to show the admin color.
2. Id like to remove the 'Re:' as well.

Any thoughts?
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: Shadow Queen on September 14, 2011, 02:04:25 PM
Very cool Blue.

1. I don't want to show the admin color.
2. Id like to remove the 'Re:' as well.

Any thoughts?

I do want to know how to remove the Re as well.
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: ccbtimewiz on September 14, 2011, 04:24:59 PM
To remove the "Re:"

Find:
Code: [Select]
' . $post['subject'];
Replace with:
Code: [Select]
' . str_ireplace('Re: ', '', $post['username']);
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: Shadow Queen on September 14, 2011, 04:32:50 PM
That work out nice :)

Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: Blue on September 14, 2011, 04:35:17 PM
1. I don't want to show the admin color.

Find and remove:
Code: [Select]
style="color: ' . $row_posts['online_color'] . ';"
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: Mick. on September 14, 2011, 04:41:51 PM
To remove the "Re:"

Find:
Code: [Select]
' . $post['subject'];
Replace with:
Code: [Select]
' . str_ireplace('Re: ', '', $post['username']);


Thanx guys! It worked.

Should be 'subject'  ;)
Code: [Select]
' . str_ireplace('Re: ', '', $post['username']);
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: ccbtimewiz on September 14, 2011, 04:55:30 PM
Oh, sorry! It copy/pasted improperly, yes keep the array key as 'subject'
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: andy on September 21, 2011, 05:56:34 AM
Using this (1.4) and the advanced whos online.
I was getting a lot of error messages - when switched off they stopped.
http://simpleportal.net/index.php?topic=9702.0

Not sure why but one thing I noticed on the recent topics/posts preview was single apostrophes
Quote
  ' 
were missing in the preview and replaced by random/garbage characters.
Lots of people using
Quote
I'm
etc.

A couple of examples on the block now....

Quote
I&#039;m comming....
I&#039;ll attend. Looking...
Andy
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: Blue on September 21, 2011, 04:21:49 PM
Try this:

Code: [Select]
<?php

/*
Block: Recent posts with post preview
Author: Blue @ Simple Portal.net
Version: 1.4
*/

/* [SETUP WHAT YOU WANT HERE] */

$topics_posts 1; // TOPICS - 1 | MESSAGES - 2
$limit 5; // How many recent posts do you want to output?
$number 70; // How many characters do you want to output?
$exclude_boards null; // IF null guests can see all boards | IF you want to hide some boards use: array( ID1, ID2, ID3) where ID is the board's ID

// Scroll Enable? Height and Speed?
$scrolling 1;       // ENABLE - 1 | DISABLE - 2
$height "150px";
$speed 3;           // SLOW - 1 | MEDIUM - 10 | FAST - 20

// Do you want to translate it to your own language? :P
$text['sportal_false'] = 'Simple Portal not found';
$text['board'] = 'in';
$text['who'] = 'by';

/* [STOP!] - THIS IS THE END OF SETUP */

//Only code from now on ;)
global $smcFunc$scripturl$sourcedir$modSettings$user_info$settings$context;

// Lets see if you are using Simple Portal. If not...well...go get them :D
if (!file_exists($sourcedir '/PortalBlocks.php'))
{
echo $text['sportal_false'];
return;
}

// Let's grab some database results
if ($topics_posts == 1) {

if (is_array($exclude_boards) || (int) $exclude_boards === $exclude_boards)
{
$exclude_boards is_array($exclude_boards) ? $exclude_boards : array($exclude_boards);
}
elseif ($exclude_boards != null)
{
$output_method $exclude_boards;
$exclude_boards = array();
}

$posts_result $smcFunc['db_query']('''
   SELECT m.poster_name, m.poster_time, m.id_msg, t.id_member_updated, m.subject, m.body, m.id_topic, b.name, t.id_last_msg, u.avatar, g.online_color,' 
. ($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'
) . '
   FROM {db_prefix}topics AS t
   LEFT JOIN {db_prefix}boards AS b ON (t.id_board = b.id_board)
   LEFT JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_last_msg)
   LEFT JOIN {db_prefix}members AS u ON (t.id_member_updated = u.id_member)
   LEFT JOIN {db_prefix}membergroups AS g ON (g.id_group = CASE WHEN u.id_group = 0 THEN u.id_post_group ELSE u.id_group END)
   ' 
. (!$user_info['is_guest'] ? '
LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = m.id_topic AND lt.id_member = ' 
$user_info['id'] . ')
LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = b.id_board AND lmr.id_member = ' 
$user_info['id'] . ')' '') . '     
   WHERE m.approved=1'   
. (empty($exclude_boards) ? '' : (!$user_info['is_guest'] ? '' '
AND b.id_board NOT IN ({array_int:exclude_boards})'
)) . '
   ORDER BY t.id_last_msg DESC
   LIMIT ' 
$limit
array(
'exclude_boards' => empty($exclude_boards) ? '' $exclude_boards,
)   
   );
$posts = array();
while (
$row_posts $smcFunc['db_fetch_assoc']($posts_result))
{

      global 
$memberContext;
      
loadMemberData($row_posts['id_member_updated']);
      
loadMemberContext($row_posts['id_member_updated']);

   
$posts[] = array(
  'id' => $row_posts['id_member_updated'],
      
'username' => '<a style="color: ' $row_posts['online_color'] . ';" href="' $scripturl '?action=profile;u=' $row_posts['id_member_updated'] . '">' $row_posts['poster_name'] . '</a>',
      
'subject' => '<a style="font-weight: bold;" title="' $text['board'] . '&nbsp;' $row_posts['name'] .'" href="' $scripturl '?topic=' $row_posts['id_topic'] . '.msg' $row_posts['id_last_msg'] . ';topicseen#new">' $row_posts['subject'] . '</a>',
      
'body' => $row_posts['body'],
  'avatar' => $row_posts['avatar'] == '' $memberContext[$row_posts['id_member_updated']]['avatar']['href'] : (stristr($row_posts['avatar'], 'http://') ? $row_posts['avatar'] : $modSettings['avatar_url'] . '/' $row_posts['avatar']),
  'board' => $row_posts['name'],
  'idboard' => $row_posts['id_board'],   
  'time' => timeformat($row_posts['poster_time']),
  'new' => !empty($row_posts['is_read'])
   );
}
$smcFunc['db_free_result']($posts_result);

} else {

if (is_array($exclude_boards) || (int) $exclude_boards === $exclude_boards)
{
$exclude_boards is_array($exclude_boards) ? $exclude_boards : array($exclude_boards);
}
elseif ($exclude_boards != null)
{
$output_method $exclude_boards;
$exclude_boards = array();
}

$posts_result $smcFunc['db_query']('''
   SELECT m.poster_name, m.poster_time, m.id_msg, m.id_member, m.subject, m.body, m.id_topic, b.name, b.id_board, u.avatar, g.online_color,' 
. ($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'
) . '
   FROM {db_prefix}messages AS m
   LEFT JOIN {db_prefix}boards AS b ON (m.id_board = b.id_board)
   LEFT JOIN {db_prefix}members AS u ON (m.id_member = u.id_member)
   LEFT JOIN {db_prefix}membergroups AS g ON (g.id_group = CASE WHEN u.id_group = 0 THEN u.id_post_group ELSE u.id_group END)
   ' 
. (!$user_info['is_guest'] ? '
LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = m.id_topic AND lt.id_member = ' 
$user_info['id'] . ')
LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = b.id_board AND lmr.id_member = ' 
$user_info['id'] . ')' '') . '   
   WHERE m.approved=1
   ORDER BY m.id_msg DESC
   LIMIT ' 
$limit);
$posts = array();
while (
$row_posts $smcFunc['db_fetch_assoc']($posts_result))
{

      global 
$memberContext;
      
loadMemberData($row_posts['id_member']);
      
loadMemberContext($row_posts['id_member']);

   
$posts[] = array(
  'id' => $row_posts['id_member'],
      
'username' => '<a style="color: ' $row_posts['online_color'] . ';" href="' $scripturl '?action=profile;u=' $row_posts['id_member'] . '">' $row_posts['poster_name'] . '</a>',
      
'subject' => '<a style="font-weight: bold;" title="' $text['board'] . '&nbsp;' $row_posts['name'] .'" href="' $scripturl '?topic=' $row_posts['id_topic'] . '.msg' $row_posts['id_msg'] . ';topicseen#new">' $row_posts['subject'] . '</a>',
      
'body' => $row_posts['body'],
  'avatar' => $row_posts['avatar'] == '' $memberContext[$row_posts['id_member']]['avatar']['href'] : (stristr($row_posts['avatar'], 'http://') ? $row_posts['avatar'] : $modSettings['avatar_url'] . '/' $row_posts['avatar']),
  'board' => $row_posts['name'],
  'idboard' => $row_posts['id_board'],   
  'time' => timeformat($row_posts['poster_time']),
  'new' => !empty($row_posts['is_read'])
   );
}
$smcFunc['db_free_result']($posts_result);

}

//Finally the Output

//Scrolling xD
if ($scrolling == 1)
echo 
'<div style="overflow: hidden;"><marquee height=' $height ' behavior="scroll" direction="up" scrollamount="' $speed '" onmouseover="this.stop()" onmouseout="this.start()">';

foreach (
$posts as $post) {

// Lets fix the BBCode bug and Strip the Text
$content1 str_replace("[""<"$post['body']);
$content2 str_replace("]"">"$content1); 
$content3 strip_tags($content2);
$preview substr ($content3,0,$number);

echo
'<table>
<tr>
<td style="width: 40px;">
<img src="' 
$post['avatar'] .'" alt="" width="40px" height="40px" />
</td>
<td>
$post['subject'];

if (!$post['new'] && $context['user']['is_logged'])
echo '&nbsp;<img src="'$settings['images_url'], '/'$context['user']['language'], '/new.gif" alt="new" border="0" />';

echo '<br />
<small>' 
$text['who'] . '&nbsp;' $post['username'] . '&nbsp;|&nbsp;' $post['time'] .'</small>
</td>
</tr>
</table>
$preview .'...
<hr />'
;
}

//Scrolling xD
if ($scrolling == 1)
echo 
'</marquee></div>';
?>
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: andy on September 21, 2011, 11:45:48 PM
Works! But still getting error messages... I dont mind unless the log number get very high in 1 day.

http://outdoorclubjapan.com/


File: /home/.../public_html/Sources/PortalBlocks.php(3384) : eval()'d code
Line: 133
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: Blue on September 23, 2011, 08:14:03 PM
I'll see what's happening and fix it ;)
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: Blue on September 24, 2011, 02:59:10 PM
Block updated to version 1.5

+ Permissons fix! (User only see what he is allowed to);
+ Exclude boards that you want
+ HTMLSPECIALCHARS to languages like Greek
+ Bug fix
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: andy on September 28, 2011, 03:01:47 AM
Used version 1.5 which works ok  but still error log
disabling the block and reloading produced no errors - enabling and reloading portal home saw the errors return. seems like 2 for each page reload for this block only. Daily log might not be as big so I can live with that.


8: Undefined index: 0

File: /home/.../public_html/Sources/PortalBlocks.php(3384) : eval()'d code
Line: 137


______________________
In whos online block also producing errors for default avatar.
8: Undefined index: default_avatar
...Sources/PortalBlocks.php(3384) : eval()'d code
Line: 106

Block name: Recent Messages (最近のメッセージ)
/* [SETUP WHAT YOU WANT HERE] */

$topics_posts = 2;      // TOPICS - 1 | MESSAGES - 2
$limit = 15;            // How many recent posts do you want to output?
$number = 25;         // How many characters do you want to output?
$exclude_boards = array( 38, 41, 53);      // IF null guests can see all boards | IF you want to hide some boards use: array( ID1, ID2, ID3) where ID is the board's ID
$htmlspecialcharacters = false; // Do you need to show html special characters like Greek characters?

// Scroll Enable? Height and Speed?
$scrolling = 2;       // ENABLE - 1 | DISABLE - 2
$height = "150px";
$speed = 3;           // SLOW - 1 | MEDIUM - 10 | FAST - 20
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: yaosurfer on October 25, 2011, 07:34:29 PM
yeap, as this custom block is on the front page I am getting hundreds of errors :/ - after disabling eval on server settings - I found the real cause of the problem which is this custom block. Error message is as follow:


8: Undefined index: 0

File: /forum/Sources/PortalBlocks.php(3351) : eval()'d code
Line: 85
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: Blue on October 26, 2011, 09:11:51 PM
I'm going to see what's happening ;)
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: wille on November 16, 2011, 02:17:45 PM
This mod is absolutely fabulous! Great indeed.

One question: If user doesn't have an avatar, is it possible to remove the blank space reserved for the image?

EDIT: Here's a solution
Find:
Code: [Select]
echo'<table>
<tr>
<td style="width: 40px;">
<img src="' . $post['avatar'] .'" alt="" width="40px" height="40px" />
</td>
<td>

Replace with:
Code: [Select]
echo'<table>
<tr>';
if (!(empty($post['avatar'])))
echo ' <td style="width: 40px;">
<img src="' . $post['avatar'] .'" alt="" width="40px" height="40px" />
</td>';
echo ' <td>
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: wille on November 16, 2011, 02:27:50 PM
One more thing, and this actually more important: can I remove everything displayed in quotes from the preview? Now the message someone is quoting looks like his own.

EDIT: The answer is:

Search:
Code: [Select]
// Lets fix the BBCode bug and Strip the Text
$content1 = str_replace("[", "<", $post['body']);

Replace with:
Code: [Select]
// Lets fix the BBCode bug and Strip the Text
$form_message = preg_replace(array('~\n?\[quote.*?\].*\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $post['body']);
$content1 = str_replace("[", "<", $form_message);
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: wille on November 16, 2011, 05:17:55 PM
I'm really inspired by this mod, so ideas keep popping up. :)

How about an AJAX implementation, i.e. recent messages updating in real time? That would rock a big time!
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: wille on November 16, 2011, 05:40:51 PM
This is a bug: If a user has display name other than his user name, user name is displayed instead.

And here's a fix:
Find (on two occassions):
Code: [Select]
SELECT m.poster_name
Replace with:
Code: [Select]
SELECT IFNULL(u.real_name, m.poster_name) AS poster_name
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: wille on November 17, 2011, 07:53:56 AM
Here's a version with following fixes:
-Remove quotes
-Remove Re:
-Show display name instead of user name
-Remove blank space if avatar not set
EDIT Added: -Avoid breaking html special characters
EDIT2: Added Strip tags function so that no one will post html on your front page

(If there's a copyright problem, I'll remove it immediatly)
Code: [Select]
<?php

/*
Block: Recent posts with post preview
Author: Blue @ Simple Portal.net
Version: 1.5
*/

/* [SETUP WHAT YOU WANT HERE] */

$topics_posts 1; // TOPICS - 1 | MESSAGES - 2
$limit 5; // How many recent posts do you want to output?
$number 140; // How many characters do you want to output?
$exclude_boards = array( 12); // IF null guests can see all boards | IF you want to hide some boards use: array( ID1, ID2, ID3) where ID is the board's ID
$htmlspecialcharacters false// Do you need to show html special characters like Greek characters?

// Scroll Enable? Height and Speed?
$scrolling 2;       // ENABLE - 1 | DISABLE - 2
$height "400px";
$speed 3;           // SLOW - 1 | MEDIUM - 10 | FAST - 20

// Do you want to translate it to your own language? :P
$text['sportal_false'] = 'Simple Portal not found';
$text['board'] = '';
$text['who'] = '';

/* [STOP!] - THIS IS THE END OF SETUP */

//Only code from now on ;)
global $smcFunc$scripturl$sourcedir$modSettings$user_info$settings$context;

// Lets see if you are using Simple Portal. If not...well...go get them :D
if (!file_exists($sourcedir '/PortalBlocks.php'))
{
echo $text['sportal_false'];
return;
}

// Let's grab some database results
if ($topics_posts == 1) {

if (is_array($exclude_boards) || (int) $exclude_boards === $exclude_boards)
{
$exclude_boards is_array($exclude_boards) ? $exclude_boards : array($exclude_boards);
}
elseif ($exclude_boards != null)
{
$output_method $exclude_boards;
$exclude_boards = array();
}

$posts_result $smcFunc['db_query']('''
   SELECT IFNULL(u.real_name, m.poster_name) AS poster_name, m.poster_time, m.id_msg, t.id_member_updated, m.subject, m.body, m.id_topic, b.name, t.id_last_msg, u.avatar, g.online_color,' 
. ($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'
) . '
   FROM {db_prefix}topics AS t
   LEFT JOIN {db_prefix}boards AS b ON (t.id_board = b.id_board)
   LEFT JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_last_msg)
   LEFT JOIN {db_prefix}members AS u ON (t.id_member_updated = u.id_member)
   LEFT JOIN {db_prefix}membergroups AS g ON (g.id_group = CASE WHEN u.id_group = 0 THEN u.id_post_group ELSE u.id_group END)
   ' 
. (!$user_info['is_guest'] ? '
LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = m.id_topic AND lt.id_member = ' 
$user_info['id'] . ')
LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = b.id_board AND lmr.id_member = ' 
$user_info['id'] . ')' '') . '     
   WHERE m.approved=1'   
. (empty($exclude_boards) ? '' '
AND b.id_board NOT IN ({array_int:exclude_boards})'
) . ' AND {query_see_board}
   ORDER BY t.id_last_msg DESC
   LIMIT ' 
$limit
array(
'exclude_boards' => empty($exclude_boards) ? '' $exclude_boards,
)   
   );
$posts = array();
while (
$row_posts $smcFunc['db_fetch_assoc']($posts_result))
{

      global 
$memberContext;
      
loadMemberData($row_posts['id_member_updated']);
      
loadMemberContext($row_posts['id_member_updated']);

   
$posts[] = array(
  'id' => $row_posts['id_member_updated'],
      
'username' => '<a style="color: ' $row_posts['online_color'] . ';" href="' $scripturl '?action=profile;u=' $row_posts['id_member_updated'] . '">' $row_posts['poster_name'] . '</a>',
      
'subject' => '<a style="font-weight: bold;" title="' $text['board'] . '&nbsp;' $row_posts['name'] .'" href="' $scripturl '?topic=' $row_posts['id_topic'] . '.msg' $row_posts['id_last_msg'] . ';topicseen#new">' $row_posts['subject'] . '</a>',
      
'body' => $row_posts['body'],
  'avatar' => $row_posts['avatar'] == '' $memberContext[$row_posts['id_member_updated']]['avatar']['href'] : (stristr($row_posts['avatar'], 'http://') ? $row_posts['avatar'] : $modSettings['avatar_url'] . '/' $row_posts['avatar']),
  'board' => $row_posts['name'], 
  'time' => timeformat($row_posts['poster_time']),
  'new' => !empty($row_posts['is_read'])
   );
}
$smcFunc['db_free_result']($posts_result);

} else {

if (is_array($exclude_boards) || (int) $exclude_boards === $exclude_boards)
{
$exclude_boards is_array($exclude_boards) ? $exclude_boards : array($exclude_boards);
}
elseif ($exclude_boards != null)
{
$output_method $exclude_boards;
$exclude_boards = array();
}

$posts_result $smcFunc['db_query']('''
   SELECT IFNULL(u.real_name, m.poster_name) AS poster_name, m.poster_time, m.id_msg, m.id_member, m.subject, m.body, m.id_topic, b.name, b.id_board, u.avatar, g.online_color,' 
. ($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'
) . '
   FROM {db_prefix}messages AS m
   LEFT JOIN {db_prefix}boards AS b ON (m.id_board = b.id_board)
   LEFT JOIN {db_prefix}members AS u ON (m.id_member = u.id_member)
   LEFT JOIN {db_prefix}membergroups AS g ON (g.id_group = CASE WHEN u.id_group = 0 THEN u.id_post_group ELSE u.id_group END)
   ' 
. (!$user_info['is_guest'] ? '
LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = m.id_topic AND lt.id_member = ' 
$user_info['id'] . ')
LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = b.id_board AND lmr.id_member = ' 
$user_info['id'] . ')' '') . '   
   WHERE m.approved=1'   
. (empty($exclude_boards) ? '' '
AND b.id_board NOT IN ({array_int:exclude_boards})'
) . ' AND {query_see_board}
   ORDER BY m.id_msg DESC
   LIMIT ' 
$limit
array(
'exclude_boards' => empty($exclude_boards) ? '' $exclude_boards,
)   
   );
$posts = array();
while (
$row_posts $smcFunc['db_fetch_assoc']($posts_result))
{

      global 
$memberContext;
      
loadMemberData($row_posts['id_member']);
      
loadMemberContext($row_posts['id_member']);

   
$posts[] = array(
  'id' => $row_posts['id_member'],
      
'username' => '<a style="color: ' $row_posts['online_color'] . ';" href="' $scripturl '?action=profile;u=' $row_posts['id_member'] . '">' $row_posts['poster_name'] . '</a>',
      
'subject' => '<a style="font-weight: bold;" title="' $text['board'] . '&nbsp;' $row_posts['name'] .'" href="' $scripturl '?topic=' $row_posts['id_topic'] . '.msg' $row_posts['id_msg'] . ';topicseen#new">' $row_posts['subject'] . '</a>',
      
'body' => $row_posts['body'],
  'avatar' => $row_posts['avatar'] == '' $memberContext[$row_posts['id_member']]['avatar']['href'] : (stristr($row_posts['avatar'], 'http://') ? $row_posts['avatar'] : $modSettings['avatar_url'] . '/' $row_posts['avatar']),
  'board' => $row_posts['name'],  
  'time' => timeformat($row_posts['poster_time']),
  'new' => !empty($row_posts['is_read'])
   );
}
$smcFunc['db_free_result']($posts_result);

}

//Finally the Output

//Scrolling xD
if ($scrolling == 1)
echo 
'<div style="overflow: hidden;"><marquee height=' $height ' behavior="scroll" direction="up" scrollamount="' $speed '" onmouseover="this.stop()" onmouseout="this.start()">';

foreach (
$posts as $post) {

// Lets fix the BBCode bug and Strip the Text
$form_message preg_replace(array('~\n?\[quote.*?\].*\[/quote\]\n?~is''~^\n~''~\[/quote\]~'), ''$post['body']);
$content1 str_replace("[""<"$form_message);
$content2 str_replace("]"">"$content1); 
$content3 strip_tags($content2);
$preview strip_tags(substr (htmlspecialchars_decode($content3),0,$number));

echo
'<table>
<tr>'
;
if (!(empty(
$post['avatar'])))
echo 
' <td style="width: 40px;">
<img src="' 
$post['avatar'] .'" alt="" width="40px" height="40px" />
</td>'
;
echo 
' <td>
str_ireplace('Re: '''$post['subject']);

if (!$post['new'] && $context['user']['is_logged'])
echo '&nbsp;<img src="'$settings['images_url'], '/'$context['user']['language'], '/new.gif" alt="new" border="0" />';

echo '<br />
<small>' 
$text['who'] . '&nbsp;' $post['username'] . '&nbsp;|&nbsp;' $post['time'] .'</small>
</td>
</tr>
</table>'
;

if ($htmlspecialcharacters) {
echo htmlspecialchars($previewENT_NOQUOTES"UTF-8") . '...';
} else {
echo $preview '...';
}

echo 
'<hr />';
}

//Scrolling xD
if ($scrolling == 1)
echo 
'</marquee></div>';
?>
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: [SiNaN] on November 17, 2011, 09:07:51 AM
I'm sure it's okay for Blue too. Thanks for your contributions. I'm sure you could help with custom coding requests too. ;)
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: Blue on November 17, 2011, 03:05:46 PM
Wow.. very nice adds :D I'm glad that you liked this mod so much and thank you for your contributions :)
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: rocknroller on November 17, 2011, 03:12:35 PM
great, i like that one: -Remove Re:   ;D
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: wille on November 19, 2011, 11:52:34 AM
It's me again :-)

If a special character is marked with html-code, it may get broken in review as in: "insert quotation here&quo...

EDIT: And here's a fix
Find:
Code: [Select]
$preview = substr ($content3,0,$number);
Replace with:
Code: [Select]
$preview = strip_tags(substr (htmlspecialchars_decode($content3),0,$number));
EDIT: added strip_tags to the code so that no one can post html-code on your frontpage.
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: [SiNaN] on November 20, 2011, 09:23:18 AM
You could use shorten_subject() function too.
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: andy on November 27, 2011, 05:54:34 AM
Just tried wille's version on 2.3.4 rc1 ... will update to final later.

No show on the front page after saving but on preview it looked ok...

/* [SETUP WHAT YOU WANT HERE] */

$topics_posts = 2;      // TOPICS - 1 | MESSAGES - 2
$limit = 15;            // How many recent posts do you want to output?
$number = 25;         // How many characters do you want to output?
$exclude_boards = array( 38, 41, 53);      // IF null guests can see all boards | IF you want to hide some boards use: array( ID1, ID2, ID3) where ID is the board's ID
$htmlspecialcharacters = false; // Do you need to show html special characters like Greek characters?

// Scroll Enable? Height and Speed?
$scrolling = 2;       // ENABLE - 1 | DISABLE - 2
$height = "450px";
$speed = 1;           // SLOW - 1 | MEDIUM - 10 | FAST - 20

// Do you want to translate it to your own language? :P
$text['sportal_false'] = 'Simple Portal not found';
$text['board'] = '';
$text['who'] = '';

/* [STOP!] - THIS IS THE END OF SETUP */
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: andy on November 27, 2011, 06:19:32 AM
It does work ... strange though. Seems when I edited - maybe first time since updating from 2.3.3 to 2.3.4, all the previous permissions were reset to disallow 'X'.  So that's why it didn't display.

Cant reproduce it but all I did was edit a custom code block with Blue's code in it which was active and working. Pasted the new code over, completed the setup configuration and saved.

It is possible that I set deactivate from block admin panel and activated again but I think all the permissions were reset on edit before that - cant be sure. Either way its strange. Deactivate and reactivate shouldn't reset the permissions to disallow either - should it?





Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: andy on November 27, 2011, 08:24:05 AM
Got it!

Seems like a bug.

When I edit a block in SP 2.3.4 and click preview, all the permissions are reset to disallow.

Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: Blue on November 30, 2011, 05:02:57 PM
When I edit a block in SP 2.3.4 and click preview, all the permissions are reset to disallow.

That's a bug from SP 2.3.4 but it'll be fixed ASAP :)
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: pixeleyes on December 23, 2011, 03:44:07 AM
I want recent posts only from specific boards.

How to make changes in coding.
 

Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: wille on December 25, 2011, 06:41:54 AM
I want recent posts only from specific boards.

How to make changes in coding.
Change

$exclude_boards = array( 1, 2, 3);

to include numbers of those boards, you don't want to see.
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: teos on January 01, 2012, 01:02:42 PM
 My request is the just the opposite :-)

  Is there a func called $include_boards= array(1,2)   ?


I need to display just one board in the block, since I have too many boards to exclude, it is very diffucult to customize  with  $exclude...

Thanks in advance

nb.. by the way, this is a great mod to be used, thanks 
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: Blue on January 02, 2012, 10:46:25 AM
I have not tested it but try it ;)

Code: [Select]
<?php

/*
Block: Recent posts with post preview
Author: Blue @ Simple Portal.net
Version: 1.5
*/

/* [SETUP WHAT YOU WANT HERE] */

$topics_posts 1; // TOPICS - 1 | MESSAGES - 2
$limit 5; // How many recent posts do you want to output?
$number 70; // How many characters do you want to output?
$included_boards null; // IF null guests can see all boards | IF you want to hide some boards use: array( ID1, ID2, ID3) where ID is the board's ID
$htmlspecialcharacters false// Do you need to show html special characters like Greek characters?

// Scroll Enable? Height and Speed?
$scrolling 1;       // ENABLE - 1 | DISABLE - 2
$height "150px";
$speed 3;           // SLOW - 1 | MEDIUM - 10 | FAST - 20

// Do you want to translate it to your own language? :P
$text['sportal_false'] = 'Simple Portal not found';
$text['board'] = 'in';
$text['who'] = 'by';

/* [STOP!] - THIS IS THE END OF SETUP */

//Only code from now on ;)
global $smcFunc$scripturl$sourcedir$modSettings$user_info$settings$context;

// Lets see if you are using Simple Portal. If not...well...go get them :D
if (!file_exists($sourcedir '/PortalBlocks.php'))
{
echo $text['sportal_false'];
return;
}

// Let's grab some database results
if ($topics_posts == 1) {

if (is_array($included_boards) || (int) $included_boards === $included_boards)
{
$included_boards is_array($included_boards) ? $included_boards : array($included_boards);
}
elseif ($included_boards != null)
{
$output_method $included_boards;
$included_boards = array();
}

$posts_result $smcFunc['db_query']('''
   SELECT m.poster_name, m.poster_time, m.id_msg, t.id_member_updated, m.subject, m.body, m.id_topic, b.name, t.id_last_msg, u.avatar, g.online_color,' 
. ($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'
) . '
   FROM {db_prefix}topics AS t
   LEFT JOIN {db_prefix}boards AS b ON (t.id_board = b.id_board)
   LEFT JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_last_msg)
   LEFT JOIN {db_prefix}members AS u ON (t.id_member_updated = u.id_member)
   LEFT JOIN {db_prefix}membergroups AS g ON (g.id_group = CASE WHEN u.id_group = 0 THEN u.id_post_group ELSE u.id_group END)
   ' 
. (!$user_info['is_guest'] ? '
LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = m.id_topic AND lt.id_member = ' 
$user_info['id'] . ')
LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = b.id_board AND lmr.id_member = ' 
$user_info['id'] . ')' '') . '     
   WHERE m.approved=1'   
. (empty($included_boards) ? '' '
AND b.id_board IN ({array_int:included_boards})'
) . ' AND {query_see_board}
   ORDER BY t.id_last_msg DESC
   LIMIT ' 
$limit
array(
'included_boards' => empty($included_boards) ? '' $included_boards,
)   
   );
$posts = array();
while (
$row_posts $smcFunc['db_fetch_assoc']($posts_result))
{

      global 
$memberContext;
      
loadMemberData($row_posts['id_member_updated']);
      
loadMemberContext($row_posts['id_member_updated']);

   
$posts[] = array(
  'id' => $row_posts['id_member_updated'],
      
'username' => '<a style="color: ' $row_posts['online_color'] . ';" href="' $scripturl '?action=profile;u=' $row_posts['id_member_updated'] . '">' $row_posts['poster_name'] . '</a>',
      
'subject' => '<a style="font-weight: bold;" title="' $text['board'] . '&nbsp;' $row_posts['name'] .'" href="' $scripturl '?topic=' $row_posts['id_topic'] . '.msg' $row_posts['id_last_msg'] . ';topicseen#new">' $row_posts['subject'] . '</a>',
      
'body' => $row_posts['body'],
  'avatar' => $row_posts['avatar'] == '' $memberContext[$row_posts['id_member_updated']]['avatar']['href'] : (stristr($row_posts['avatar'], 'http://') ? $row_posts['avatar'] : $modSettings['avatar_url'] . '/' $row_posts['avatar']),
  'board' => $row_posts['name'], 
  'time' => timeformat($row_posts['poster_time']),
  'new' => !empty($row_posts['is_read'])
   );
}
$smcFunc['db_free_result']($posts_result);

} else {

if (is_array($included_boards) || (int) $included_boards === $included_boards)
{
$included_boards is_array($included_boards) ? $included_boards : array($included_boards);
}
elseif ($included_boards != null)
{
$output_method $included_boards;
$included_boards = array();
}

$posts_result $smcFunc['db_query']('''
   SELECT m.poster_name, m.poster_time, m.id_msg, m.id_member, m.subject, m.body, m.id_topic, b.name, b.id_board, u.avatar, g.online_color,' 
. ($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'
) . '
   FROM {db_prefix}messages AS m
   LEFT JOIN {db_prefix}boards AS b ON (m.id_board = b.id_board)
   LEFT JOIN {db_prefix}members AS u ON (m.id_member = u.id_member)
   LEFT JOIN {db_prefix}membergroups AS g ON (g.id_group = CASE WHEN u.id_group = 0 THEN u.id_post_group ELSE u.id_group END)
   ' 
. (!$user_info['is_guest'] ? '
LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = m.id_topic AND lt.id_member = ' 
$user_info['id'] . ')
LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = b.id_board AND lmr.id_member = ' 
$user_info['id'] . ')' '') . '   
   WHERE m.approved=1'   
. (empty($included_boards) ? '' '
AND b.id_board NOT IN ({array_int:included_boards})'
) . ' AND {query_see_board}
   ORDER BY m.id_msg DESC
   LIMIT ' 
$limit
array(
'included_boards' => empty($included_boards) ? '' $included_boards,
)   
   );
$posts = array();
while (
$row_posts $smcFunc['db_fetch_assoc']($posts_result))
{

      global 
$memberContext;
      
loadMemberData($row_posts['id_member']);
      
loadMemberContext($row_posts['id_member']);

   
$posts[] = array(
  'id' => $row_posts['id_member'],
      
'username' => '<a style="color: ' $row_posts['online_color'] . ';" href="' $scripturl '?action=profile;u=' $row_posts['id_member'] . '">' $row_posts['poster_name'] . '</a>',
      
'subject' => '<a style="font-weight: bold;" title="' $text['board'] . '&nbsp;' $row_posts['name'] .'" href="' $scripturl '?topic=' $row_posts['id_topic'] . '.msg' $row_posts['id_msg'] . ';topicseen#new">' $row_posts['subject'] . '</a>',
      
'body' => $row_posts['body'],
  'avatar' => $row_posts['avatar'] == '' $memberContext[$row_posts['id_member']]['avatar']['href'] : (stristr($row_posts['avatar'], 'http://') ? $row_posts['avatar'] : $modSettings['avatar_url'] . '/' $row_posts['avatar']),
  'board' => $row_posts['name'],  
  'time' => timeformat($row_posts['poster_time']),
  'new' => !empty($row_posts['is_read'])
   );
}
$smcFunc['db_free_result']($posts_result);

}

//Finally the Output

//Scrolling xD
if ($scrolling == 1)
echo 
'<div style="overflow: hidden;"><marquee height=' $height ' behavior="scroll" direction="up" scrollamount="' $speed '" onmouseover="this.stop()" onmouseout="this.start()">';

foreach (
$posts as $post) {

// Lets fix the BBCode bug and Strip the Text
$content1 str_replace("[""<"$post['body']);
$content2 str_replace("]"">"$content1); 
$content3 strip_tags($content2);
$preview substr ($content3,0,$number);

echo
'<table>
<tr>
<td style="width: 40px;">
<img src="' 
$post['avatar'] .'" alt="" width="40px" height="40px" />
</td>
<td>
$post['subject'];

if (!$post['new'] && $context['user']['is_logged'])
echo '&nbsp;<img src="'$settings['images_url'], '/'$context['user']['language'], '/new.gif" alt="new" border="0" />';

echo '<br />
<small>' 
$text['who'] . '&nbsp;' $post['username'] . '&nbsp;|&nbsp;' $post['time'] .'</small>
</td>
</tr>
</table>'
;

if ($htmlspecialcharacters) {
echo htmlspecialchars($previewENT_NOQUOTES"UTF-8") . '...';
} else {
echo $preview '...';
}

echo 
'<hr />';
}

//Scrolling xD
if ($scrolling == 1)
echo 
'</marquee></div>';
?>
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: teos on January 02, 2012, 10:54:00 AM
  Works great.  Thanks alot Blue ...
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: BaghdadGhost on January 03, 2012, 11:13:50 PM
this is great tweak.

I use v1.4 for the avatar but only have one problem with arabic language some of the characters show like &nbsp;

thanks
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: Blue on January 04, 2012, 07:37:05 PM
Can you send me a screenshot in order to see what's the problem? :)
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: BaghdadGhost on January 04, 2012, 07:39:05 PM
here you go thanks


Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: Blue on January 04, 2012, 08:13:54 PM
&nbsp; is the code for "space" between two words. The problem is that in your screenshot the code does not appear right.

Let's try this:
Code: [Select]
<?php

/*
Block: Recent posts with post preview
Author: Blue @ Simple Portal.net
Version: 1.5
*/

/* [SETUP WHAT YOU WANT HERE] */

$topics_posts 1; // TOPICS - 1 | MESSAGES - 2
$limit 5; // How many recent posts do you want to output?
$number 70; // How many characters do you want to output?
$included_boards null; // IF null guests can see all boards | IF you want to hide some boards use: array( ID1, ID2, ID3) where ID is the board's ID
$htmlspecialcharacters false// Do you need to show html special characters like Greek characters?

// Scroll Enable? Height and Speed?
$scrolling 1;       // ENABLE - 1 | DISABLE - 2
$height "150px";
$speed 3;           // SLOW - 1 | MEDIUM - 10 | FAST - 20

// Do you want to translate it to your own language? :P
$text['sportal_false'] = 'Simple Portal not found';
$text['board'] = 'in';
$text['who'] = 'by';

/* [STOP!] - THIS IS THE END OF SETUP */

//Only code from now on ;)
global $smcFunc$scripturl$sourcedir$modSettings$user_info$settings$context;

// Lets see if you are using Simple Portal. If not...well...go get them :D
if (!file_exists($sourcedir '/PortalBlocks.php'))
{
echo $text['sportal_false'];
return;
}

// Let's grab some database results
if ($topics_posts == 1) {

if (is_array($included_boards) || (int) $included_boards === $included_boards)
{
$included_boards is_array($included_boards) ? $included_boards : array($included_boards);
}
elseif ($included_boards != null)
{
$output_method $included_boards;
$included_boards = array();
}

$posts_result $smcFunc['db_query']('''
   SELECT m.poster_name, m.poster_time, m.id_msg, t.id_member_updated, m.subject, m.body, m.id_topic, b.name, t.id_last_msg, u.avatar, g.online_color,' 
. ($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'
) . '
   FROM {db_prefix}topics AS t
   LEFT JOIN {db_prefix}boards AS b ON (t.id_board = b.id_board)
   LEFT JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_last_msg)
   LEFT JOIN {db_prefix}members AS u ON (t.id_member_updated = u.id_member)
   LEFT JOIN {db_prefix}membergroups AS g ON (g.id_group = CASE WHEN u.id_group = 0 THEN u.id_post_group ELSE u.id_group END)
   ' 
. (!$user_info['is_guest'] ? '
LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = m.id_topic AND lt.id_member = ' 
$user_info['id'] . ')
LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = b.id_board AND lmr.id_member = ' 
$user_info['id'] . ')' '') . '     
   WHERE m.approved=1'   
. (empty($included_boards) ? '' '
AND b.id_board IN ({array_int:included_boards})'
) . ' AND {query_see_board}
   ORDER BY t.id_last_msg DESC
   LIMIT ' 
$limit
array(
'included_boards' => empty($included_boards) ? '' $included_boards,
)   
   );
$posts = array();
while (
$row_posts $smcFunc['db_fetch_assoc']($posts_result))
{

      global 
$memberContext;
      
loadMemberData($row_posts['id_member_updated']);
      
loadMemberContext($row_posts['id_member_updated']);

   
$posts[] = array(
  'id' => $row_posts['id_member_updated'],
      
'username' => '<a style="color: ' $row_posts['online_color'] . ';" href="' $scripturl '?action=profile;u=' $row_posts['id_member_updated'] . '">' $row_posts['poster_name'] . '</a>',
      
'subject' => '<a style="font-weight: bold;" title="' $text['board'] . '&nbsp;' $row_posts['name'] .'" href="' $scripturl '?topic=' $row_posts['id_topic'] . '.msg' $row_posts['id_last_msg'] . ';topicseen#new">' $row_posts['subject'] . '</a>',
      
'body' => $row_posts['body'],
  'avatar' => $row_posts['avatar'] == '' $memberContext[$row_posts['id_member_updated']]['avatar']['href'] : (stristr($row_posts['avatar'], 'http://') ? $row_posts['avatar'] : $modSettings['avatar_url'] . '/' $row_posts['avatar']),
  'board' => $row_posts['name'], 
  'time' => timeformat($row_posts['poster_time']),
  'new' => !empty($row_posts['is_read'])
   );
}
$smcFunc['db_free_result']($posts_result);

} else {

if (is_array($included_boards) || (int) $included_boards === $included_boards)
{
$included_boards is_array($included_boards) ? $included_boards : array($included_boards);
}
elseif ($included_boards != null)
{
$output_method $included_boards;
$included_boards = array();
}

$posts_result $smcFunc['db_query']('''
   SELECT m.poster_name, m.poster_time, m.id_msg, m.id_member, m.subject, m.body, m.id_topic, b.name, b.id_board, u.avatar, g.online_color,' 
. ($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'
) . '
   FROM {db_prefix}messages AS m
   LEFT JOIN {db_prefix}boards AS b ON (m.id_board = b.id_board)
   LEFT JOIN {db_prefix}members AS u ON (m.id_member = u.id_member)
   LEFT JOIN {db_prefix}membergroups AS g ON (g.id_group = CASE WHEN u.id_group = 0 THEN u.id_post_group ELSE u.id_group END)
   ' 
. (!$user_info['is_guest'] ? '
LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = m.id_topic AND lt.id_member = ' 
$user_info['id'] . ')
LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = b.id_board AND lmr.id_member = ' 
$user_info['id'] . ')' '') . '   
   WHERE m.approved=1'   
. (empty($included_boards) ? '' '
AND b.id_board NOT IN ({array_int:included_boards})'
) . ' AND {query_see_board}
   ORDER BY m.id_msg DESC
   LIMIT ' 
$limit
array(
'included_boards' => empty($included_boards) ? '' $included_boards,
)   
   );
$posts = array();
while (
$row_posts $smcFunc['db_fetch_assoc']($posts_result))
{

      global 
$memberContext;
      
loadMemberData($row_posts['id_member']);
      
loadMemberContext($row_posts['id_member']);

   
$posts[] = array(
  'id' => $row_posts['id_member'],
      
'username' => '<a style="color: ' $row_posts['online_color'] . ';" href="' $scripturl '?action=profile;u=' $row_posts['id_member'] . '">' $row_posts['poster_name'] . '</a>',
      
'subject' => '<a style="font-weight: bold;" title="' $text['board'] . '&nbsp;' $row_posts['name'] .'" href="' $scripturl '?topic=' $row_posts['id_topic'] . '.msg' $row_posts['id_msg'] . ';topicseen#new">' $row_posts['subject'] . '</a>',
      
'body' => $row_posts['body'],
  'avatar' => $row_posts['avatar'] == '' $memberContext[$row_posts['id_member']]['avatar']['href'] : (stristr($row_posts['avatar'], 'http://') ? $row_posts['avatar'] : $modSettings['avatar_url'] . '/' $row_posts['avatar']),
  'board' => $row_posts['name'],  
  'time' => timeformat($row_posts['poster_time']),
  'new' => !empty($row_posts['is_read'])
   );
}
$smcFunc['db_free_result']($posts_result);

}

//Finally the Output

//Scrolling xD
if ($scrolling == 1)
echo 
'<div style="overflow: hidden;"><marquee height=' $height ' behavior="scroll" direction="up" scrollamount="' $speed '" onmouseover="this.stop()" onmouseout="this.start()">';

foreach (
$posts as $post) {

// Lets fix the BBCode bug and Strip the Text
$content1 str_replace("[""<"$post['body']);
$content2 str_replace("]"">"$content1); 
$content3 strip_tags($content2);
$preview substr ($content3,0,$number);

echo
'<table>
<tr>
<td style="width: 40px;">
<img src="' 
$post['avatar'] .'" alt="" width="40px" height="40px" />
</td>
<td>
$post['subject'];

if (!$post['new'] && $context['user']['is_logged'])
echo '&nbsp;<img src="'$settings['images_url'], '/'$context['user']['language'], '/new.gif" alt="new" border="0" />';

echo '<br />
<small>' 
$text['who'] . '&nbsp;' $post['username'] . '&nbsp;|&nbsp;' $post['time'] .'</small>
</td>
</tr>
</table>'
;

if ($htmlspecialcharacters) {
echo htmlspecialchars($previewENT_QUOTES ENT_IGNORE"UTF-8") . '...';
} else {
echo $preview '...';
}

echo 
'<hr />';
}

//Scrolling xD
if ($scrolling == 1)
echo 
'</marquee></div>';
?>
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: BaghdadGhost on January 04, 2012, 08:16:23 PM
because its right to left lol

look at this shot

meanwhile let e try the code you provided


Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: BaghdadGhost on January 04, 2012, 08:20:03 PM
now I am getting the ? sign


look at this

thanks

Edit: can you please make changes on v1.4 I like it for the default avatar link
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: Andree2401 on January 07, 2012, 12:22:42 PM
@Blue: Great work, works like a charm.
But i have one Feature Request.
In my Forum i use this Mod to show the recent Topics.
Is it possible to add Information in which Board the Topic was posted?
Actualy i could only see this Infos:
 who, when, Subject and Text

but not where the Thread is posted.

I use this Code (a few Pages back in this Thread)
Code: [Select]
<?php

/*
Block: Recent posts with post preview
Author: Blue @ Simple Portal.net
Version: 1.5
*/

/* [SETUP WHAT YOU WANT HERE] */

$topics_posts 1;  // TOPICS - 1 | MESSAGES - 2
$limit 5;  // How many recent posts do you want to output?
$number 140;  // How many characters do you want to output?
$exclude_boards = array( 12);  // IF null guests can see all boards | IF you want to hide some boards use: array( ID1, ID2, ID3) where ID is the board's ID
$htmlspecialcharacters false// Do you need to show html special characters like Greek characters?

// Scroll Enable? Height and Speed?
$scrolling 2;       // ENABLE - 1 | DISABLE - 2
$height "400px";
$speed 3;           // SLOW - 1 | MEDIUM - 10 | FAST - 20

// Do you want to translate it to your own language? :P
$text['sportal_false'] = 'Simple Portal not found';
$text['board'] = '';
$text['who'] = '';

/* [STOP!] - THIS IS THE END OF SETUP */

//Only code from now on ;)
global $smcFunc$scripturl$sourcedir$modSettings$user_info$settings$context;

// Lets see if you are using Simple Portal. If not...well...go get them :D
if (!file_exists($sourcedir '/PortalBlocks.php'))
{
 echo $text['sportal_false'];
 return;
}

// Let's grab some database results
if ($topics_posts == 1) {

 if (is_array($exclude_boards) || (int) $exclude_boards === $exclude_boards)
 {
 $exclude_boards is_array($exclude_boards) ? $exclude_boards : array($exclude_boards);
 }
 elseif ($exclude_boards != null)
 {
 $output_method $exclude_boards;
 $exclude_boards = array();
 }

$posts_result $smcFunc['db_query']('''
   SELECT IFNULL(u.real_name, m.poster_name) AS poster_name, m.poster_time, m.id_msg, t.id_member_updated, m.subject, m.body, m.id_topic, b.name, t.id_last_msg, u.avatar, g.online_color,' 
. ($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'
) . '
   FROM {db_prefix}topics AS t
   LEFT JOIN {db_prefix}boards AS b ON (t.id_board = b.id_board)
   LEFT JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_last_msg)
   LEFT JOIN {db_prefix}members AS u ON (t.id_member_updated = u.id_member)
   LEFT JOIN {db_prefix}membergroups AS g ON (g.id_group = CASE WHEN u.id_group = 0 THEN u.id_post_group ELSE u.id_group END)
   ' 
. (!$user_info['is_guest'] ? '
 LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = m.id_topic AND lt.id_member = ' 
$user_info['id'] . ')
 LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = b.id_board AND lmr.id_member = ' 
$user_info['id'] . ')' '') . '     
   WHERE m.approved=1'   
. (empty($exclude_boards) ? '' '
 AND b.id_board NOT IN ({array_int:exclude_boards})'
) . ' AND {query_see_board}
   ORDER BY t.id_last_msg DESC
   LIMIT ' 
$limit
 array(
 'exclude_boards' => empty($exclude_boards) ? '' $exclude_boards,
 )   
   );
$posts = array();
while (
$row_posts $smcFunc['db_fetch_assoc']($posts_result))
{

      global 
$memberContext;
      
loadMemberData($row_posts['id_member_updated']);
      
loadMemberContext($row_posts['id_member_updated']);

   
$posts[] = array(
   'id' => $row_posts['id_member_updated'],
      
'username' => '<a style="color: ' $row_posts['online_color'] . ';" href="' $scripturl '?action=profile;u=' $row_posts['id_member_updated'] . '">' $row_posts['poster_name'] . '</a>',
      
'subject' => '<a style="font-weight: bold;" title="' $text['board'] . '&nbsp;' $row_posts['name'] .'" href="' $scripturl '?topic=' $row_posts['id_topic'] . '.msg' $row_posts['id_last_msg'] . ';topicseen#new">' $row_posts['subject'] . '</a>',
      
'body' => $row_posts['body'],
   'avatar' => $row_posts['avatar'] == '' $memberContext[$row_posts['id_member_updated']]['avatar']['href'] : (stristr($row_posts['avatar'], 'http://') ? $row_posts['avatar'] : $modSettings['avatar_url'] . '/' $row_posts['avatar']),
   'board' => $row_posts['name'], 
   'time' => timeformat($row_posts['poster_time']),
   'new' => !empty($row_posts['is_read'])
   );
}
$smcFunc['db_free_result']($posts_result);

} else {

 if (is_array($exclude_boards) || (int) $exclude_boards === $exclude_boards)
 {
 $exclude_boards is_array($exclude_boards) ? $exclude_boards : array($exclude_boards);
 }
 elseif ($exclude_boards != null)
 {
 $output_method $exclude_boards;
 $exclude_boards = array();
 }

$posts_result $smcFunc['db_query']('''
   SELECT IFNULL(u.real_name, m.poster_name) AS poster_name, m.poster_time, m.id_msg, m.id_member, m.subject, m.body, m.id_topic, b.name, b.id_board, u.avatar, g.online_color,' 
. ($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'
) . '
   FROM {db_prefix}messages AS m
   LEFT JOIN {db_prefix}boards AS b ON (m.id_board = b.id_board)
   LEFT JOIN {db_prefix}members AS u ON (m.id_member = u.id_member)
   LEFT JOIN {db_prefix}membergroups AS g ON (g.id_group = CASE WHEN u.id_group = 0 THEN u.id_post_group ELSE u.id_group END)
   ' 
. (!$user_info['is_guest'] ? '
 LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = m.id_topic AND lt.id_member = ' 
$user_info['id'] . ')
 LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = b.id_board AND lmr.id_member = ' 
$user_info['id'] . ')' '') . '   
   WHERE m.approved=1'   
. (empty($exclude_boards) ? '' '
 AND b.id_board NOT IN ({array_int:exclude_boards})'
) . ' AND {query_see_board}
   ORDER BY m.id_msg DESC
   LIMIT ' 
$limit
 array(
 'exclude_boards' => empty($exclude_boards) ? '' $exclude_boards,
 )   
   );
$posts = array();
while (
$row_posts $smcFunc['db_fetch_assoc']($posts_result))
{

      global 
$memberContext;
      
loadMemberData($row_posts['id_member']);
      
loadMemberContext($row_posts['id_member']);

   
$posts[] = array(
   'id' => $row_posts['id_member'],
      
'username' => '<a style="color: ' $row_posts['online_color'] . ';" href="' $scripturl '?action=profile;u=' $row_posts['id_member'] . '">' $row_posts['poster_name'] . '</a>',
      
'subject' => '<a style="font-weight: bold;" title="' $text['board'] . '&nbsp;' $row_posts['name'] .'" href="' $scripturl '?topic=' $row_posts['id_topic'] . '.msg' $row_posts['id_msg'] . ';topicseen#new">' $row_posts['subject'] . '</a>',
      
'body' => $row_posts['body'],
   'avatar' => $row_posts['avatar'] == '' $memberContext[$row_posts['id_member']]['avatar']['href'] : (stristr($row_posts['avatar'], 'http://') ? $row_posts['avatar'] : $modSettings['avatar_url'] . '/' $row_posts['avatar']),
   'board' => $row_posts['name'],  
   'time' => timeformat($row_posts['poster_time']),
   'new' => !empty($row_posts['is_read'])
   );
}
$smcFunc['db_free_result']($posts_result);

}

//Finally the Output

//Scrolling xD
if ($scrolling == 1)
echo 
'<div style="overflow: hidden;"><marquee height=' $height ' behavior="scroll" direction="up" scrollamount="' $speed '" onmouseover="this.stop()" onmouseout="this.start()">';

foreach (
$posts as $post) {

// Lets fix the BBCode bug and Strip the Text
 
$form_message preg_replace(array('~\n?\[quote.*?\].*\[/quote\]\n?~is''~^\n~''~\[/quote\]~'), ''$post['body']);
$content1 str_replace("[""<"$form_message);
$content2 str_replace("]"">"$content1); 
$content3 strip_tags($content2);
$preview strip_tags(substr (htmlspecialchars_decode($content3),0,$number));

echo
'<table>
 <tr>'
;
if (!(empty(
$post['avatar'])))
echo 
'  <td style="width: 40px;">
 <img src="' 
$post['avatar'] .'" alt="" width="40px" height="40px" />
 </td>'
;
echo 
'  <td>
 ' 
str_ireplace('Re: '''$post['subject']);

 if (!$post['new'] && $context['user']['is_logged'])
 echo '&nbsp;<img src="'$settings['images_url'], '/'$context['user']['language'], '/new.gif" alt="new" border="0" />';

 echo '<br />
 <small>' 
$text['who'] . '&nbsp;' $post['username'] . '&nbsp;|&nbsp;' $post['time'] .'</small>
 </td>
 </tr>
 </table>'
;

 if ($htmlspecialcharacters) {
 echo htmlspecialchars($previewENT_NOQUOTES"UTF-8") . '...';
 } else {
 echo $preview '...';
 }

echo 
'<hr />';
 }

//Scrolling xD
if ($scrolling == 1)
echo 
'</marquee></div>';
 ?>

Thanks an again GOOD Work

Andree
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: pixeleyes on February 10, 2012, 12:22:44 PM
I was looking for that feature too.

But I just want to show red marked features.
 
Subject
Poster - Date (Don't want time)
Board
(Don't want post text)
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: Yngwiedis on April 04, 2012, 06:45:09 AM
Hello...

Is there anyway to hide some boards from guests but not from other users?

Thank you very very much.
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: batterydoc on April 04, 2012, 02:29:26 PM
Hi,
maybe a stupid question,
I am interested how to get out of each topic, view the last 3 messages.

 8)
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: Kryzen on April 10, 2012, 05:21:39 AM
Hey Blue, could you please take a look at this topic:
http://simpleportal.net/index.php?topic=11043
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: weerforum on April 14, 2012, 04:19:43 AM
Hey Blue, could you please take a look at this topic:
http://simpleportal.net/index.php?topic=11043

No need for this Blue
I solved it.
I pruned te shoutbox and it was good.
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: Yngwiedis on April 17, 2012, 08:18:11 AM
Hello...

Is there anyway to hide some boards from guests but not from other users?

Thank you very very much.

Up...
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: batterydoc on April 17, 2012, 09:02:09 AM
Hi,
maybe a stupid question,
I am interested how to get out of each topic, view the last 3 messages.

 8)

 :(
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: Yngwiedis on May 01, 2012, 08:30:07 PM
Hello...

Is there anyway to hide some boards from guests but not from other users?

Thank you very very much.

Up...
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: andy on May 02, 2012, 02:25:16 AM
In SMF, boards already have permissions settings to hide from guests or any user group.
If you use this block it will only display topics and replies based on the user group permissions for each board.

If you want the board accessible to guests but a different display in the blocks then...
You could make 2 identical blocks - set one block visible to guests only and select only the board IDs (in the settings) you want to display to guests. Make a 2nd block in the same position but only make it visible to user groups you want to see it.. In that you put in all the board IDs for them.

After users login the block changes from the restricted one only visible to guests to the one visible only to users with more boards visible.


Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: weerforum on May 15, 2012, 05:36:53 PM
Is it possible to make it without a avatar show ?
See attachment
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: weerforum on May 31, 2012, 05:31:50 PM
Hello i have it made like this now but i get this .........
Quote
Pas filter toe: Toon alleen de foutmeldingen van deze URL
http://weerforum.eu/forum/index.php?
Pas filter toe: Toon alleen de fouten met hetzelfde bericht
8: Undefined index:
Pas filter toe: Toon alleen fouten van dit bestand
Bestand: /home/weerforu/domains/weerforum.eu/public_html/forum/Sources/PortalBlocks.php(3561) : eval()'d code
Regel: 175


Code: [Select]
<?php

/*
Block: Recent posts with post preview
Author: Blue @ Simple Portal.net
Version: 1.5
*/

/* [SETUP WHAT YOU WANT HERE] */

$topics_posts 1;  // TOPICS - 1 | MESSAGES - 2
$limit 30;  // How many recent posts do you want to output?
$number 50;  // How many characters do you want to output?
$exclude_boards = array( 0);  // IF null guests can see all boards | IF you want to hide some boards use: array( ID1, ID2, ID3) where ID is the board's ID
$htmlspecialcharacters false// Do you need to show html special characters like Greek characters?

// Scroll Enable? Height and Speed?
$scrolling 1;       // ENABLE - 1 | DISABLE - 2
$height "410px";
$speed 3;           // SLOW - 1 | MEDIUM - 10 | FAST - 20

// Do you want to translate it to your own language? :P
$text['sportal_false'] = 'Simple Portal not found';
$text['board'] = '';
$text['who'] = '';

/* [STOP!] - THIS IS THE END OF SETUP */

//Only code from now on ;)
global $smcFunc$scripturl$sourcedir$modSettings$user_info$settings$context;

// Lets see if you are using Simple Portal. If not...well...go get them :D
if (!file_exists($sourcedir '/PortalBlocks.php'))
{
 echo $text['sportal_false'];
 return;
}

// Let's grab some database results
if ($topics_posts == 1) {

 if (is_array($exclude_boards) || (int) $exclude_boards === $exclude_boards)
 {
 $exclude_boards is_array($exclude_boards) ? $exclude_boards : array($exclude_boards);
 }
 elseif ($exclude_boards != null)
 {
 $output_method $exclude_boards;
 $exclude_boards = array();
 }

$posts_result $smcFunc['db_query']('''
   SELECT IFNULL(u.real_name, m.poster_name) AS poster_name, m.poster_time, m.id_msg, t.id_member_updated, m.subject, m.body, m.id_topic, b.name, t.id_last_msg, u.avatar, g.online_color,' 
. ($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'
) . '
   FROM {db_prefix}topics AS t
   LEFT JOIN {db_prefix}boards AS b ON (t.id_board = b.id_board)
   LEFT JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_last_msg)
   LEFT JOIN {db_prefix}members AS u ON (t.id_member_updated = u.id_member)
   LEFT JOIN {db_prefix}membergroups AS g ON (g.id_group = CASE WHEN u.id_group = 0 THEN u.id_post_group ELSE u.id_group END)
   ' 
. (!$user_info['is_guest'] ? '
 LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = m.id_topic AND lt.id_member = ' 
$user_info['id'] . ')
 LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = b.id_board AND lmr.id_member = ' 
$user_info['id'] . ')' '') . '     
   WHERE m.approved=1'   
. (empty($exclude_boards) ? '' '
 AND b.id_board NOT IN ({array_int:exclude_boards})'
) . ' AND {query_see_board}
   ORDER BY t.id_last_msg DESC
   LIMIT ' 
$limit
 array(
 'exclude_boards' => empty($exclude_boards) ? '' $exclude_boards,
 )   
   );
$posts = array();
while (
$row_posts $smcFunc['db_fetch_assoc']($posts_result))
{

      global 
$memberContext;
      
loadMemberData($row_posts['id_member_updated']);
      
loadMemberContext($row_posts['id_member_updated']);

   
$posts[] = array(
   'id' => $row_posts['id_member_updated'],
      
'username' => '<a style="color: ' $row_posts['online_color'] . ';" href="' $scripturl '?action=profile;u=' $row_posts['id_member_updated'] . '">' $row_posts['poster_name'] . '</a>',
      
'subject' => '<a style="font-weight: bold;" title="' $text['board'] . '&nbsp;' $row_posts['name'] .'" href="' $scripturl '?topic=' $row_posts['id_topic'] . '.msg' $row_posts['id_last_msg'] . ';topicseen#new">' $row_posts['subject'] . '</a>',
      
'body' => $row_posts['body'],
   'avatar' => $row_posts['avatar'] == '' $memberContext[$row_posts['id_member_updated']]['avatar']['href'] : (stristr($row_posts['avatar'], 'http://') ? $row_posts['avatar'] : $modSettings['avatar_url'] . '/' $row_posts['avatar']),
   'board' => $row_posts['name'], 
   'time' => timeformat($row_posts['poster_time']),
   'new' => !empty($row_posts['is_read'])
   );
}
$smcFunc['db_free_result']($posts_result);

} else {

 if (is_array($exclude_boards) || (int) $exclude_boards === $exclude_boards)
 {
 $exclude_boards is_array($exclude_boards) ? $exclude_boards : array($exclude_boards);
 }
 elseif ($exclude_boards != null)
 {
 $output_method $exclude_boards;
 $exclude_boards = array();
 }

$posts_result $smcFunc['db_query']('''
   SELECT IFNULL(u.real_name, m.poster_name) AS poster_name, m.poster_time, m.id_msg, m.id_member, m.subject, m.body, m.id_topic, b.name, b.id_board, u.avatar, g.online_color,' 
. ($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'
) . '
   FROM {db_prefix}messages AS m
   LEFT JOIN {db_prefix}boards AS b ON (m.id_board = b.id_board)
   LEFT JOIN {db_prefix}members AS u ON (m.id_member = u.id_member)
   LEFT JOIN {db_prefix}membergroups AS g ON (g.id_group = CASE WHEN u.id_group = 0 THEN u.id_post_group ELSE u.id_group END)
   ' 
. (!$user_info['is_guest'] ? '
 LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = m.id_topic AND lt.id_member = ' 
$user_info['id'] . ')
 LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = b.id_board AND lmr.id_member = ' 
$user_info['id'] . ')' '') . '   
   WHERE m.approved=1'   
. (empty($exclude_boards) ? '' '
 AND b.id_board NOT IN ({array_int:exclude_boards})'
) . ' AND {query_see_board}
   ORDER BY m.id_msg DESC
   LIMIT ' 
$limit
 array(
 'exclude_boards' => empty($exclude_boards) ? '' $exclude_boards,
 )   
   );
$posts = array();
while (
$row_posts $smcFunc['db_fetch_assoc']($posts_result))
{

      global 
$memberContext;
      
loadMemberData($row_posts['id_member']);
      
loadMemberContext($row_posts['id_member']);

   
$posts[] = array(
   'id' => $row_posts['id_member'],
      
'username' => '<a style="color: ' $row_posts['online_color'] . ';" href="' $scripturl '?action=profile;u=' $row_posts['id_member'] . '">' $row_posts['poster_name'] . '</a>',
      
'subject' => '<a style="font-weight: bold;" title="' $text['board'] . '&nbsp;' $row_posts['name'] .'" href="' $scripturl '?topic=' $row_posts['id_topic'] . '.msg' $row_posts['id_msg'] . ';topicseen#new">' $row_posts['subject'] . '</a>',
      
'body' => $row_posts['body'],
   'avatar' => $row_posts['avatar'] == '' $memberContext[$row_posts['id_member']]['avatar']['href'] : (stristr($row_posts['avatar'], 'http://') ? $row_posts['avatar'] : $modSettings['avatar_url'] . '/' $row_posts['avatar']),
   'board' => $row_posts['name'],  
   'time' => timeformat($row_posts['poster_time']),
   'new' => !empty($row_posts['is_read'])
   );
}
$smcFunc['db_free_result']($posts_result);

}

//Finally the Output

//Scrolling xD
if ($scrolling == 1)
echo 
'<div style="overflow: hidden;"><marquee height=' $height ' behavior="scroll" direction="up" scrollamount="' $speed '" onmouseover="this.stop()" onmouseout="this.start()">';

foreach (
$posts as $post) {

// Lets fix the BBCode bug and Strip the Text
 
$form_message preg_replace(array('~\n?\[quote.*?\].*\[/quote\]\n?~is''~^\n~''~\[/quote\]~'), ''$post['body']);
$content1 str_replace("[""<"$form_message);
$content2 str_replace("]"">"$content1); 
$content3 strip_tags($content2);
$preview strip_tags(substr (htmlspecialchars_decode($content3),0,$number));

echo
'<table>
 <tr>'
;
if (!(empty(
$post['avatar'])))
echo 
'  <td style="width: 0px;">
 <img src="' 
$post['avatar'] .'" alt="" width="0px" height="0px" />
 </td>'
;
echo 
'  <td>
 ' 
str_ireplace('Re: '''$post['subject']);

 if (!$post['new'] && $context['user']['is_logged'])
 echo '&nbsp;<img src="'$settings['images_url'], '/'$context['user']['language'], '/new.gif" alt="new" border="0" />';

 echo '<br />
 <small>' 
$text['who'] . '&nbsp;' $post[''] . '&nbsp;|&nbsp;' $post['time'] .'</small>
 </td>
 </tr>
 </table>'
;

 if ($htmlspecialcharacters) {
 echo htmlspecialchars($previewENT_NOQUOTES"UTF-8") . '...';
 } else {
 echo $preview '...';
 }

echo 
'<hr />';
 }

//Scrolling xD
if ($scrolling == 1)
echo 
'</marquee></div>';
 ?>

Dr. Deejay: Added code tags :)
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: Kryzen on May 31, 2012, 05:36:29 PM
I have no idea what it's supposed to do, but this should fix it:
Code: [Select]
<?php

/*
Block: Recent posts with post preview
Author: Blue @ Simple Portal.net
Version: 1.5
*/

/* [SETUP WHAT YOU WANT HERE] */

$topics_posts 1;  // TOPICS - 1 | MESSAGES - 2
$limit 30;  // How many recent posts do you want to output?
$number 50;  // How many characters do you want to output?
$exclude_boards = array( 0);  // IF null guests can see all boards | IF you want to hide some boards use: array( ID1, ID2, ID3) where ID is the board's ID
$htmlspecialcharacters false// Do you need to show html special characters like Greek characters?

// Scroll Enable? Height and Speed?
$scrolling 1;       // ENABLE - 1 | DISABLE - 2
$height "410px";
$speed 3;           // SLOW - 1 | MEDIUM - 10 | FAST - 20

// Do you want to translate it to your own language? :P
$text['sportal_false'] = 'Simple Portal not found';
$text['board'] = '';
$text['who'] = '';

/* [STOP!] - THIS IS THE END OF SETUP */

//Only code from now on ;)
global $smcFunc$scripturl$sourcedir$modSettings$user_info$settings$context;

// Lets see if you are using Simple Portal. If not...well...go get them :D
if (!file_exists($sourcedir '/PortalBlocks.php'))
{
 echo $text['sportal_false'];
 return;
}

// Let's grab some database results
if ($topics_posts == 1) {

 if (is_array($exclude_boards) || (int) $exclude_boards === $exclude_boards)
 {
 $exclude_boards is_array($exclude_boards) ? $exclude_boards : array($exclude_boards);
 }
 elseif ($exclude_boards != null)
 {
 $output_method $exclude_boards;
 $exclude_boards = array();
 }

$posts_result $smcFunc['db_query']('''
   SELECT IFNULL(u.real_name, m.poster_name) AS poster_name, m.poster_time, m.id_msg, t.id_member_updated, m.subject, m.body, m.id_topic, b.name, t.id_last_msg, u.avatar, g.online_color,' 
. ($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'
) . '
   FROM {db_prefix}topics AS t
   LEFT JOIN {db_prefix}boards AS b ON (t.id_board = b.id_board)
   LEFT JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_last_msg)
   LEFT JOIN {db_prefix}members AS u ON (t.id_member_updated = u.id_member)
   LEFT JOIN {db_prefix}membergroups AS g ON (g.id_group = CASE WHEN u.id_group = 0 THEN u.id_post_group ELSE u.id_group END)
   ' 
. (!$user_info['is_guest'] ? '
 LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = m.id_topic AND lt.id_member = ' 
$user_info['id'] . ')
 LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = b.id_board AND lmr.id_member = ' 
$user_info['id'] . ')' '') . '     
   WHERE m.approved=1'   
. (empty($exclude_boards) ? '' '
 AND b.id_board NOT IN ({array_int:exclude_boards})'
) . ' AND {query_see_board}
   ORDER BY t.id_last_msg DESC
   LIMIT ' 
$limit
 array(
 'exclude_boards' => empty($exclude_boards) ? '' $exclude_boards,
 )   
   );
$posts = array();
while (
$row_posts $smcFunc['db_fetch_assoc']($posts_result))
{

      global 
$memberContext;
      
loadMemberData($row_posts['id_member_updated']);
      
loadMemberContext($row_posts['id_member_updated']);

   
$posts[] = array(
   'id' => $row_posts['id_member_updated'],
      
'username' => '<a style="color: ' $row_posts['online_color'] . ';" href="' $scripturl '?action=profile;u=' $row_posts['id_member_updated'] . '">' $row_posts['poster_name'] . '</a>',
      
'subject' => '<a style="font-weight: bold;" title="' $text['board'] . '&nbsp;' $row_posts['name'] .'" href="' $scripturl '?topic=' $row_posts['id_topic'] . '.msg' $row_posts['id_last_msg'] . ';topicseen#new">' $row_posts['subject'] . '</a>',
      
'body' => $row_posts['body'],
   'avatar' => $row_posts['avatar'] == '' $memberContext[$row_posts['id_member_updated']]['avatar']['href'] : (stristr($row_posts['avatar'], 'http://') ? $row_posts['avatar'] : $modSettings['avatar_url'] . '/' $row_posts['avatar']),
   'board' => $row_posts['name'], 
   'time' => timeformat($row_posts['poster_time']),
   'new' => !empty($row_posts['is_read'])
   );
}
$smcFunc['db_free_result']($posts_result);

} else {

 if (is_array($exclude_boards) || (int) $exclude_boards === $exclude_boards)
 {
 $exclude_boards is_array($exclude_boards) ? $exclude_boards : array($exclude_boards);
 }
 elseif ($exclude_boards != null)
 {
 $output_method $exclude_boards;
 $exclude_boards = array();
 }

$posts_result $smcFunc['db_query']('''
   SELECT IFNULL(u.real_name, m.poster_name) AS poster_name, m.poster_time, m.id_msg, m.id_member, m.subject, m.body, m.id_topic, b.name, b.id_board, u.avatar, g.online_color,' 
. ($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'
) . '
   FROM {db_prefix}messages AS m
   LEFT JOIN {db_prefix}boards AS b ON (m.id_board = b.id_board)
   LEFT JOIN {db_prefix}members AS u ON (m.id_member = u.id_member)
   LEFT JOIN {db_prefix}membergroups AS g ON (g.id_group = CASE WHEN u.id_group = 0 THEN u.id_post_group ELSE u.id_group END)
   ' 
. (!$user_info['is_guest'] ? '
 LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = m.id_topic AND lt.id_member = ' 
$user_info['id'] . ')
 LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = b.id_board AND lmr.id_member = ' 
$user_info['id'] . ')' '') . '   
   WHERE m.approved=1'   
. (empty($exclude_boards) ? '' '
 AND b.id_board NOT IN ({array_int:exclude_boards})'
) . ' AND {query_see_board}
   ORDER BY m.id_msg DESC
   LIMIT ' 
$limit
 array(
 'exclude_boards' => empty($exclude_boards) ? '' $exclude_boards,
 )   
   );
$posts = array();
while (
$row_posts $smcFunc['db_fetch_assoc']($posts_result))
{

      global 
$memberContext;
      
loadMemberData($row_posts['id_member']);
      
loadMemberContext($row_posts['id_member']);

   
$posts[] = array(
   'id' => $row_posts['id_member'],
      
'username' => '<a style="color: ' $row_posts['online_color'] . ';" href="' $scripturl '?action=profile;u=' $row_posts['id_member'] . '">' $row_posts['poster_name'] . '</a>',
      
'subject' => '<a style="font-weight: bold;" title="' $text['board'] . '&nbsp;' $row_posts['name'] .'" href="' $scripturl '?topic=' $row_posts['id_topic'] . '.msg' $row_posts['id_msg'] . ';topicseen#new">' $row_posts['subject'] . '</a>',
      
'body' => $row_posts['body'],
   'avatar' => $row_posts['avatar'] == '' $memberContext[$row_posts['id_member']]['avatar']['href'] : (stristr($row_posts['avatar'], 'http://') ? $row_posts['avatar'] : $modSettings['avatar_url'] . '/' $row_posts['avatar']),
   'board' => $row_posts['name'],  
   'time' => timeformat($row_posts['poster_time']),
   'new' => !empty($row_posts['is_read'])
   );
}
$smcFunc['db_free_result']($posts_result);

}

//Finally the Output

//Scrolling xD
if ($scrolling == 1)
echo 
'<div style="overflow: hidden;"><marquee height=' $height ' behavior="scroll" direction="up" scrollamount="' $speed '" onmouseover="this.stop()" onmouseout="this.start()">';

foreach (
$posts as $post) {

// Lets fix the BBCode bug and Strip the Text
 
$form_message preg_replace(array('~\n?\[quote.*?\].*\[/quote\]\n?~is''~^\n~''~\[/quote\]~'), ''$post['body']);
$content1 str_replace("[""<"$form_message);
$content2 str_replace("]"">"$content1); 
$content3 strip_tags($content2);
$preview strip_tags(substr (htmlspecialchars_decode($content3),0,$number));

echo
'<table>
 <tr>'
;
if (!(empty(
$post['avatar'])))
echo 
'  <td style="width: 0px;">
 <img src="' 
$post['avatar'] .'" alt="" width="0px" height="0px" />
 </td>'
;
echo 
'  <td>
 ' 
str_ireplace('Re: '''$post['subject']);

 if (!$post['new'] && $context['user']['is_logged'])
 echo '&nbsp;<img src="'$settings['images_url'], '/'$context['user']['language'], '/new.gif" alt="new" border="0" />';

 echo '<br />
 <small>' 
$text['who'] . '&nbsp;' $post['username'] . '&nbsp;|&nbsp;' $post['time'] .'</small>
 </td>
 </tr>
 </table>'
;

 if ($htmlspecialcharacters) {
 echo htmlspecialchars($previewENT_NOQUOTES"UTF-8") . '...';
 } else {
 echo $preview '...';
 }

echo 
'<hr />';
 }

//Scrolling xD
if ($scrolling == 1)
echo 
'</marquee></div>';
 ?>
:)
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: weerforum on May 31, 2012, 05:46:46 PM
Is it possible to NOT show the username ?
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: Kryzen on May 31, 2012, 05:48:47 PM
Sure, then this should do it:
Code: [Select]
<?php

/*
Block: Recent posts with post preview
Author: Blue @ Simple Portal.net
Version: 1.5
*/

/* [SETUP WHAT YOU WANT HERE] */

$topics_posts 1;  // TOPICS - 1 | MESSAGES - 2
$limit 30;  // How many recent posts do you want to output?
$number 50;  // How many characters do you want to output?
$exclude_boards = array( 0);  // IF null guests can see all boards | IF you want to hide some boards use: array( ID1, ID2, ID3) where ID is the board's ID
$htmlspecialcharacters false// Do you need to show html special characters like Greek characters?

// Scroll Enable? Height and Speed?
$scrolling 1;       // ENABLE - 1 | DISABLE - 2
$height "410px";
$speed 3;           // SLOW - 1 | MEDIUM - 10 | FAST - 20

// Do you want to translate it to your own language? :P
$text['sportal_false'] = 'Simple Portal not found';
$text['board'] = '';
$text['who'] = '';

/* [STOP!] - THIS IS THE END OF SETUP */

//Only code from now on ;)
global $smcFunc$scripturl$sourcedir$modSettings$user_info$settings$context;

// Lets see if you are using Simple Portal. If not...well...go get them :D
if (!file_exists($sourcedir '/PortalBlocks.php'))
{
 echo $text['sportal_false'];
 return;
}

// Let's grab some database results
if ($topics_posts == 1) {

 if (is_array($exclude_boards) || (int) $exclude_boards === $exclude_boards)
 {
 $exclude_boards is_array($exclude_boards) ? $exclude_boards : array($exclude_boards);
 }
 elseif ($exclude_boards != null)
 {
 $output_method $exclude_boards;
 $exclude_boards = array();
 }

$posts_result $smcFunc['db_query']('''
   SELECT IFNULL(u.real_name, m.poster_name) AS poster_name, m.poster_time, m.id_msg, t.id_member_updated, m.subject, m.body, m.id_topic, b.name, t.id_last_msg, u.avatar, g.online_color,' 
. ($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'
) . '
   FROM {db_prefix}topics AS t
   LEFT JOIN {db_prefix}boards AS b ON (t.id_board = b.id_board)
   LEFT JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_last_msg)
   LEFT JOIN {db_prefix}members AS u ON (t.id_member_updated = u.id_member)
   LEFT JOIN {db_prefix}membergroups AS g ON (g.id_group = CASE WHEN u.id_group = 0 THEN u.id_post_group ELSE u.id_group END)
   ' 
. (!$user_info['is_guest'] ? '
 LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = m.id_topic AND lt.id_member = ' 
$user_info['id'] . ')
 LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = b.id_board AND lmr.id_member = ' 
$user_info['id'] . ')' '') . '     
   WHERE m.approved=1'   
. (empty($exclude_boards) ? '' '
 AND b.id_board NOT IN ({array_int:exclude_boards})'
) . ' AND {query_see_board}
   ORDER BY t.id_last_msg DESC
   LIMIT ' 
$limit
 array(
 'exclude_boards' => empty($exclude_boards) ? '' $exclude_boards,
 )   
   );
$posts = array();
while (
$row_posts $smcFunc['db_fetch_assoc']($posts_result))
{

      global 
$memberContext;
      
loadMemberData($row_posts['id_member_updated']);
      
loadMemberContext($row_posts['id_member_updated']);

   
$posts[] = array(
   'id' => $row_posts['id_member_updated'],
      
'username' => '<a style="color: ' $row_posts['online_color'] . ';" href="' $scripturl '?action=profile;u=' $row_posts['id_member_updated'] . '">' $row_posts['poster_name'] . '</a>',
      
'subject' => '<a style="font-weight: bold;" title="' $text['board'] . '&nbsp;' $row_posts['name'] .'" href="' $scripturl '?topic=' $row_posts['id_topic'] . '.msg' $row_posts['id_last_msg'] . ';topicseen#new">' $row_posts['subject'] . '</a>',
      
'body' => $row_posts['body'],
   'avatar' => $row_posts['avatar'] == '' $memberContext[$row_posts['id_member_updated']]['avatar']['href'] : (stristr($row_posts['avatar'], 'http://') ? $row_posts['avatar'] : $modSettings['avatar_url'] . '/' $row_posts['avatar']),
   'board' => $row_posts['name'], 
   'time' => timeformat($row_posts['poster_time']),
   'new' => !empty($row_posts['is_read'])
   );
}
$smcFunc['db_free_result']($posts_result);

} else {

 if (is_array($exclude_boards) || (int) $exclude_boards === $exclude_boards)
 {
 $exclude_boards is_array($exclude_boards) ? $exclude_boards : array($exclude_boards);
 }
 elseif ($exclude_boards != null)
 {
 $output_method $exclude_boards;
 $exclude_boards = array();
 }

$posts_result $smcFunc['db_query']('''
   SELECT IFNULL(u.real_name, m.poster_name) AS poster_name, m.poster_time, m.id_msg, m.id_member, m.subject, m.body, m.id_topic, b.name, b.id_board, u.avatar, g.online_color,' 
. ($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'
) . '
   FROM {db_prefix}messages AS m
   LEFT JOIN {db_prefix}boards AS b ON (m.id_board = b.id_board)
   LEFT JOIN {db_prefix}members AS u ON (m.id_member = u.id_member)
   LEFT JOIN {db_prefix}membergroups AS g ON (g.id_group = CASE WHEN u.id_group = 0 THEN u.id_post_group ELSE u.id_group END)
   ' 
. (!$user_info['is_guest'] ? '
 LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = m.id_topic AND lt.id_member = ' 
$user_info['id'] . ')
 LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = b.id_board AND lmr.id_member = ' 
$user_info['id'] . ')' '') . '   
   WHERE m.approved=1'   
. (empty($exclude_boards) ? '' '
 AND b.id_board NOT IN ({array_int:exclude_boards})'
) . ' AND {query_see_board}
   ORDER BY m.id_msg DESC
   LIMIT ' 
$limit
 array(
 'exclude_boards' => empty($exclude_boards) ? '' $exclude_boards,
 )   
   );
$posts = array();
while (
$row_posts $smcFunc['db_fetch_assoc']($posts_result))
{

      global 
$memberContext;
      
loadMemberData($row_posts['id_member']);
      
loadMemberContext($row_posts['id_member']);

   
$posts[] = array(
   'id' => $row_posts['id_member'],
      
'username' => '<a style="color: ' $row_posts['online_color'] . ';" href="' $scripturl '?action=profile;u=' $row_posts['id_member'] . '">' $row_posts['poster_name'] . '</a>',
      
'subject' => '<a style="font-weight: bold;" title="' $text['board'] . '&nbsp;' $row_posts['name'] .'" href="' $scripturl '?topic=' $row_posts['id_topic'] . '.msg' $row_posts['id_msg'] . ';topicseen#new">' $row_posts['subject'] . '</a>',
      
'body' => $row_posts['body'],
   'avatar' => $row_posts['avatar'] == '' $memberContext[$row_posts['id_member']]['avatar']['href'] : (stristr($row_posts['avatar'], 'http://') ? $row_posts['avatar'] : $modSettings['avatar_url'] . '/' $row_posts['avatar']),
   'board' => $row_posts['name'],  
   'time' => timeformat($row_posts['poster_time']),
   'new' => !empty($row_posts['is_read'])
   );
}
$smcFunc['db_free_result']($posts_result);

}

//Finally the Output

//Scrolling xD
if ($scrolling == 1)
echo 
'<div style="overflow: hidden;"><marquee height=' $height ' behavior="scroll" direction="up" scrollamount="' $speed '" onmouseover="this.stop()" onmouseout="this.start()">';

foreach (
$posts as $post) {

// Lets fix the BBCode bug and Strip the Text
 
$form_message preg_replace(array('~\n?\[quote.*?\].*\[/quote\]\n?~is''~^\n~''~\[/quote\]~'), ''$post['body']);
$content1 str_replace("[""<"$form_message);
$content2 str_replace("]"">"$content1); 
$content3 strip_tags($content2);
$preview strip_tags(substr (htmlspecialchars_decode($content3),0,$number));

echo
'<table>
 <tr>'
;
if (!(empty(
$post['avatar'])))
echo 
'  <td style="width: 0px;">
 <img src="' 
$post['avatar'] .'" alt="" width="0px" height="0px" />
 </td>'
;
echo 
'  <td>
 ' 
str_ireplace('Re: '''$post['subject']);

 if (!$post['new'] && $context['user']['is_logged'])
 echo '&nbsp;<img src="'$settings['images_url'], '/'$context['user']['language'], '/new.gif" alt="new" border="0" />';

 echo '<br />
 <small>' 
$post['time'] .'</small>
 </td>
 </tr>
 </table>'
;

 if ($htmlspecialcharacters) {
 echo htmlspecialchars($previewENT_NOQUOTES"UTF-8") . '...';
 } else {
 echo $preview '...';
 }

echo 
'<hr />';
 }

//Scrolling xD
if ($scrolling == 1)
echo 
'</marquee></div>';
 ?>
:)
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: weerforum on May 31, 2012, 05:51:43 PM
Yes thnx Dr Deejay  :D :D :D
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: Kryzen on May 31, 2012, 05:54:37 PM
You're welcome, glad to help :)
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: Atletico on July 28, 2012, 07:39:58 AM
I want to not to show context. How can I do it ?
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: phantomm on July 28, 2012, 07:55:15 AM
you mean message content?
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: Atletico on July 28, 2012, 08:05:07 AM
Yes, because, pictures and videos are not be shown and it looks bad.

For example, "http://www.bilim.org/wp-content/uploads/su_basinc.jpgSizce donarken ge..."
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: phantomm on July 28, 2012, 08:17:07 AM
Find:
Code: [Select]
if ($htmlspecialcharacters) {
echo htmlspecialchars($preview, ENT_NOQUOTES, "UTF-8") . '...';
} else {
echo $preview . '...';
}

Replace with:
Code: [Select]
//if ($htmlspecialcharacters) {
//echo htmlspecialchars($preview, ENT_NOQUOTES, "UTF-8") . '...';
//} else {
//echo $preview . '...';
//}
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: Atletico on July 28, 2012, 08:26:16 AM
Thanks :)
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: Atletico on July 28, 2012, 09:01:09 AM
Another question;

I deleted marquee and I want to use <hr /> code. But, it should not be shown aftr last line. How can I do it ?

Code: [Select]
<?php

/*
Block: Recent posts with post preview
Author: Blue @ Simple Portal.net
Version: 1.5
*/

/* [SETUP WHAT YOU WANT HERE] */

$topics_posts 1; // TOPICS - 1 | MESSAGES - 2
$limit 5; // How many recent posts do you want to output?
$number 70; // How many characters do you want to output?
$exclude_boards null; // IF null guests can see all boards | IF you want to hide some boards use: array( ID1, ID2, ID3) where ID is the board's ID
$htmlspecialcharacters false// Do you need to show html special characters like Greek characters?

// Scroll Enable? Height and Speed?
$scrolling 1;       // ENABLE - 1 | DISABLE - 2
$height "250px";
$speed 3;           // SLOW - 1 | MEDIUM - 10 | FAST - 20

// Do you want to translate it to your own language? :P
$text['sportal_false'] = 'Simple Portal not found';
$text['board'] = 'in';
$text['who'] = 'Gönderen:';

/* [STOP!] - THIS IS THE END OF SETUP */

//Only code from now on ;)
global $smcFunc$scripturl$sourcedir$modSettings$user_info$settings$context;

// Lets see if you are using Simple Portal. If not...well...go get them :D
if (!file_exists($sourcedir '/PortalBlocks.php'))
{
echo $text['sportal_false'];
return;
}

// Let's grab some database results
if ($topics_posts == 1) {

if (is_array($exclude_boards) || (int) $exclude_boards === $exclude_boards)
{
$exclude_boards is_array($exclude_boards) ? $exclude_boards : array($exclude_boards);
}
elseif ($exclude_boards != null)
{
$output_method $exclude_boards;
$exclude_boards = array();
}

$posts_result $smcFunc['db_query']('''
   SELECT m.poster_name, m.poster_time, m.id_msg, t.id_member_updated, m.subject, m.body, m.id_topic, b.name, t.id_last_msg, u.avatar, g.online_color,' 
. ($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'
) . '
   FROM {db_prefix}topics AS t
   LEFT JOIN {db_prefix}boards AS b ON (t.id_board = b.id_board)
   LEFT JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_last_msg)
   LEFT JOIN {db_prefix}members AS u ON (t.id_member_updated = u.id_member)
   LEFT JOIN {db_prefix}membergroups AS g ON (g.id_group = CASE WHEN u.id_group = 0 THEN u.id_post_group ELSE u.id_group END)
   ' 
. (!$user_info['is_guest'] ? '
LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = m.id_topic AND lt.id_member = ' 
$user_info['id'] . ')
LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = b.id_board AND lmr.id_member = ' 
$user_info['id'] . ')' '') . '     
   WHERE m.approved=1'   
. (empty($exclude_boards) ? '' '
AND b.id_board NOT IN ({array_int:exclude_boards})'
) . ' AND {query_see_board}
   ORDER BY t.id_last_msg DESC
   LIMIT ' 
$limit
array(
'exclude_boards' => empty($exclude_boards) ? '' $exclude_boards,
)   
   );
$posts = array();
while (
$row_posts $smcFunc['db_fetch_assoc']($posts_result))
{

      global 
$memberContext;
      
loadMemberData($row_posts['id_member_updated']);
      
loadMemberContext($row_posts['id_member_updated']);

   
$posts[] = array(
  'id' => $row_posts['id_member_updated'],
      
'username' => '<a style="color: ' $row_posts['online_color'] . ';" href="' $scripturl '?action=profile;u=' $row_posts['id_member_updated'] . '">' $row_posts['poster_name'] . '</a>',
      
'subject' => '<a style="font-weight: bold;" title="' $text['board'] . '&nbsp;' $row_posts['name'] .'" href="' $scripturl '?topic=' $row_posts['id_topic'] . '.msg' $row_posts['id_last_msg'] . ';topicseen#new">' $row_posts['subject'] . '</a>',
      
'body' => $row_posts['body'],
  'avatar' => $row_posts['avatar'] == '' $memberContext[$row_posts['id_member_updated']]['avatar']['href'] : (stristr($row_posts['avatar'], 'http://') ? $row_posts['avatar'] : $modSettings['avatar_url'] . '/' $row_posts['avatar']),
  'board' => $row_posts['name'], 
  'time' => timeformat($row_posts['poster_time']),
  'new' => !empty($row_posts['is_read'])
   );
}
$smcFunc['db_free_result']($posts_result);

} else {

if (is_array($exclude_boards) || (int) $exclude_boards === $exclude_boards)
{
$exclude_boards is_array($exclude_boards) ? $exclude_boards : array($exclude_boards);
}
elseif ($exclude_boards != null)
{
$output_method $exclude_boards;
$exclude_boards = array();
}

$posts_result $smcFunc['db_query']('''
   SELECT m.poster_name, m.poster_time, m.id_msg, m.id_member, m.subject, m.body, m.id_topic, b.name, b.id_board, u.avatar, g.online_color,' 
. ($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'
) . '
   FROM {db_prefix}messages AS m
   LEFT JOIN {db_prefix}boards AS b ON (m.id_board = b.id_board)
   LEFT JOIN {db_prefix}members AS u ON (m.id_member = u.id_member)
   LEFT JOIN {db_prefix}membergroups AS g ON (g.id_group = CASE WHEN u.id_group = 0 THEN u.id_post_group ELSE u.id_group END)
   ' 
. (!$user_info['is_guest'] ? '
LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = m.id_topic AND lt.id_member = ' 
$user_info['id'] . ')
LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = b.id_board AND lmr.id_member = ' 
$user_info['id'] . ')' '') . '   
   WHERE m.approved=1'   
. (empty($exclude_boards) ? '' '
AND b.id_board NOT IN ({array_int:exclude_boards})'
) . ' AND {query_see_board}
   ORDER BY m.id_msg DESC
   LIMIT ' 
$limit
array(
'exclude_boards' => empty($exclude_boards) ? '' $exclude_boards,
)   
   );
$posts = array();
while (
$row_posts $smcFunc['db_fetch_assoc']($posts_result))
{

      global 
$memberContext;
      
loadMemberData($row_posts['id_member']);
      
loadMemberContext($row_posts['id_member']);

   
$posts[] = array(
  'id' => $row_posts['id_member'],
      
'username' => '<a style="color: ' $row_posts['online_color'] . ';" href="' $scripturl '?action=profile;u=' $row_posts['id_member'] . '">' $row_posts['poster_name'] . '</a>',
      
'subject' => '<a style="font-weight: bold;" title="' $text['board'] . '&nbsp;' $row_posts['name'] .'" href="' $scripturl '?topic=' $row_posts['id_topic'] . '.msg' $row_posts['id_msg'] . ';topicseen#new">' $row_posts['subject'] . '</a>',
      
'body' => $row_posts['body'],
  'avatar' => $row_posts['avatar'] == '' $memberContext[$row_posts['id_member']]['avatar']['href'] : (stristr($row_posts['avatar'], 'http://') ? $row_posts['avatar'] : $modSettings['avatar_url'] . '/' $row_posts['avatar']),
  'board' => $row_posts['name'],  
  'time' => timeformat($row_posts['poster_time']),
  'new' => !empty($row_posts['is_read'])
   );
}
$smcFunc['db_free_result']($posts_result);

}

//Finally the Output

//Scrolling xD
if ($scrolling == 1)
echo 
'<div style="overflow: hidden;">';

foreach (
$posts as $post) {

// Lets fix the BBCode bug and Strip the Text
$content1 str_replace("[""<"$post['body']);
$content2 str_replace("]"">"$content1); 
$content3 strip_tags($content2);
$preview substr ($content3,0,$number);

echo
'<table>
<tr>
<td style="width: 40px; height: 40px;" >
<img src="' 
$post['avatar'] .'" alt="" width="30px" height="30px" />
</td>
<td>
$post['subject'];

if (!$post['new'] && $context['user']['is_logged'])
echo '&nbsp;<img src="'$settings['images_url'], '/'$context['user']['language'], '/new.gif" alt="new" border="0" />';

echo '<br />
<small>' 
$text['who'] . '&nbsp;' $post['username'] . '&nbsp;|&nbsp;' $post['time'] .'</small>
</td>
</tr>
</table>'
;

//if ($htmlspecialcharacters) {
//echo htmlspecialchars($preview, ENT_NOQUOTES, "UTF-8") . '...';
//} else {
//echo $preview . '...';
//}

echo '';
}

//Scrolling xD
if ($scrolling == 1)
echo 
'</div>';
?>

And I want to resize avatars; not 30px height and weight.
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: kimyaci on August 08, 2012, 12:37:02 PM
Thanks for this block.I was a little changed.I want to show the first pictures in this block.How can I do it ? Thanks.

(http://img4.hostingpics.net/pics/631809ScreenShot021.png) (http://www.hostingpics.net/viewer.php?id=631809ScreenShot021.png)

Code: [Select]
<?php

/*
Block: Recent posts with post preview
Author: Blue @ Simple Portal.net
Version: 1.5
*/

/* [SETUP WHAT YOU WANT HERE] */

$topics_posts 2;  // TOPICS - 1 | MESSAGES - 2
$limit 20;  // How many recent posts do you want to output?
$number 0;  // How many characters do you want to output?
$exclude_boards = array(318427426432425433424,423431434430,429);  // IF null guests can see all boards | IF you want to hide some boards use: array( ID1, ID2, ID3) where ID is the board's ID
$htmlspecialcharacters =true// Do you need to show html special characters like Greek characters?
$default_avatar 'http://img15.hostingpics.net/pics/282198defaultavatar.png';

// Scroll Enable? Height and Speed?
$scrolling 1;       // ENABLE - 1 | DISABLE - 2
$height "400px";
$speed 1;           // SLOW - 1 | MEDIUM - 10 | FAST - 20

// Do you want to translate it to your own language? :P
$text['sportal_false'] = 'Simple Portal not found';
$text['board'] = '';
$text['who'] = '';

/* [STOP!] - THIS IS THE END OF SETUP */

//Only code from now on ;)
global $smcFunc$scripturl$sourcedir$modSettings$user_info$settings$context;

// Lets see if you are using Simple Portal. If not...well...go get them :D
if (!file_exists($sourcedir '/PortalBlocks.php'))
{
 echo $text['sportal_false'];
 return;
}

// Let's grab some database results
if ($topics_posts == 1) {

 if (is_array($exclude_boards) || (int) $exclude_boards === $exclude_boards)
 {
 $exclude_boards is_array($exclude_boards) ? $exclude_boards : array($exclude_boards);
 }
 elseif ($exclude_boards != null)
 {
 $output_method $exclude_boards;
 $exclude_boards = array();
 }

$posts_result $smcFunc['db_query']('''
   SELECT m.poster_name, m.poster_time, m.id_msg, t.id_member_updated, m.subject, m.body, m.id_topic, b.name, t.id_last_msg, u.avatar, g.online_color,' 
. ($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'
) . '
   FROM {db_prefix}topics AS t
   LEFT JOIN {db_prefix}boards AS b ON (t.id_board = b.id_board)
   LEFT JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_last_msg)
   LEFT JOIN {db_prefix}members AS u ON (t.id_member_updated = u.id_member)
   LEFT JOIN {db_prefix}membergroups AS g ON (g.id_group = CASE WHEN u.id_group = 0 THEN u.id_post_group ELSE u.id_group END)
   ' 
. (!$user_info['is_guest'] ? '
 LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = m.id_topic AND lt.id_member = ' 
$user_info['id'] . ')
 LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = b.id_board AND lmr.id_member = ' 
$user_info['id'] . ')' '') . '     
   WHERE m.approved=1'   
. (empty($exclude_boards) ? '' '
 AND b.id_board NOT IN ({array_int:exclude_boards})'
) . ' AND {query_see_board}
   ORDER BY t.id_last_msg DESC
   LIMIT ' 
$limit
 array(
 'exclude_boards' => empty($exclude_boards) ? '' $exclude_boards,
 )   
   );
$posts = array();
while (
$row_posts $smcFunc['db_fetch_assoc']($posts_result))
{

      global 
$memberContext;
      
loadMemberData($row_posts['id_member_updated']);
      
loadMemberContext($row_posts['id_member_updated']);

   
$posts[] = array(
   'id' => $row_posts['id_member_updated'],
      
'username' => '<a style="color: ' $row_posts['online_color'] . ';" href="' $scripturl '?action=profile;u=' $row_posts['id_member_updated'] . '">' $row_posts['poster_name'] . '</a>',
      
'subject' => '<a style="font-weight: bold;" title="' $text['board'] . ' ' $row_posts['name'] .'" href="' $scripturl '?topic=' $row_posts['id_topic'] . '.msg' $row_posts['id_last_msg'] . ';topicseen#new">' $row_posts['subject'] . '</a>',
      
'body' => $row_posts['body'],
   'avatar' => $row_posts['avatar'] == '' $memberContext[$row_posts['id_member_updated']]['avatar']['href'] : (stristr($row_posts['avatar'], 'http://') ? $row_posts['avatar'] : $modSettings['avatar_url'] . '/' $row_posts['avatar']),
   'board' => $row_posts['name'], 
   'time' => timeformat($row_posts['poster_time']),
   'new' => !empty($row_posts['is_read'])
   );
}
$smcFunc['db_free_result']($posts_result);

} else {

 if (is_array($exclude_boards) || (int) $exclude_boards === $exclude_boards)
 {
 $exclude_boards is_array($exclude_boards) ? $exclude_boards : array($exclude_boards);
 }
 elseif ($exclude_boards != null)
 {
 $output_method $exclude_boards;
 $exclude_boards = array();
 }

$posts_result $smcFunc['db_query']('''
   SELECT m.poster_name, m.poster_time, m.id_msg, m.id_member, m.subject, m.body, m.id_topic, b.name, b.id_board, u.avatar, g.online_color,' 
. ($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'
) . '
   FROM {db_prefix}messages AS m
   LEFT JOIN {db_prefix}boards AS b ON (m.id_board = b.id_board)
   LEFT JOIN {db_prefix}members AS u ON (m.id_member = u.id_member)
   LEFT JOIN {db_prefix}membergroups AS g ON (g.id_group = CASE WHEN u.id_group = 0 THEN u.id_post_group ELSE u.id_group END)
   ' 
. (!$user_info['is_guest'] ? '
 LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = m.id_topic AND lt.id_member = ' 
$user_info['id'] . ')
 LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = b.id_board AND lmr.id_member = ' 
$user_info['id'] . ')' '') . '   
   WHERE m.approved=1'   
. (empty($exclude_boards) ? '' '
 AND b.id_board NOT IN ({array_int:exclude_boards})'
) . ' AND {query_see_board}
   ORDER BY m.id_msg DESC
   LIMIT ' 
$limit
 array(
 'exclude_boards' => empty($exclude_boards) ? '' $exclude_boards,
 )   
   );
$posts = array();
while (
$row_posts $smcFunc['db_fetch_assoc']($posts_result))
{

      global 
$memberContext;
      
loadMemberData($row_posts['id_member']);
      
loadMemberContext($row_posts['id_member']);

   
$posts[] = array(
   'id' => $row_posts['id_member'],
      
'username' => '<a style="color: ' $row_posts['online_color'] . ';" href="' $scripturl '?action=profile;u=' $row_posts['id_member'] . '">' $row_posts['poster_name'] . '</a>',
      
'subject' => '<a style="font-weight: bold;" title="' $text['board'] . ' ' $row_posts['name'] .'" href="' $scripturl '?topic=' $row_posts['id_topic'] . '.msg' $row_posts['id_msg'] . ';topicseen#new">' $row_posts['subject'] . '</a>',
      
'body' => $row_posts['body'],
    'avatar' => $row_posts['avatar'] == '' $memberContext[$row_posts['id_member']]['avatar']['href'] : (stristr($row_posts['avatar'], 'http://') ? $row_posts['avatar'] : $modSettings['avatar_url'] . '/' $row_posts['avatar']),
   'board' => $row_posts['name'],  
   'time' => timeformat($row_posts['poster_time']),
   'new' => !empty($row_posts['is_read'])
   );
}
$smcFunc['db_free_result']($posts_result);

}

//Finally the Output

//Scrolling xD
if ($scrolling == 1)
echo 
'                                        <div style="overflow: hidden;"><marquee height=' $height ' behavior="scroll" direction="up" scrollamount="' $speed '" onmouseover="this.stop()" onmouseout="this.start()">';

foreach (
$posts as $post) {

// Lets fix the BBCode bug and Strip the Text
 
$form_message preg_replace(array('~\n?\[quote.*?\].*\[/quote\]\n?~is''~^\n~''~\[/quote\]~'), ''$post['body']);
$content1 str_replace("[""<"$form_message);
$content2 str_replace("]"">"$content1); 
$content3 strip_tags($content2);
$preview strip_tags(substr (htmlspecialchars_decode($content3),0,$number));

echo
'
<div class="mansetdeneme" width="width: 220px;" align="left">
<table>
 <tr>
 <td style="width: 40px;">'
;
               if (!empty(
$post['avatar'])){
echo'
<div class="manseta"> 
<img src="' 
$post['avatar'] .'" alt="" width="40px" height="24px" /></div>';

else {
echo '
<div class="manseta">
<img src="' 
$default_avatar .'" alt="" width="40px" height="24px" /></div>';
}
echo 
' </td>
       <td>
 ' 
str_ireplace('Re: '''$post['subject']);

 if (!$post['new'] && $context['user']['is_logged'])
 echo ' <span><div class="mansetg"><img src="'$settings['images_url'], '/'$context['user']['language'], '/new.gif" alt="new" border="0" /></div></span>';

 echo '<br />
 <small>' 
$text['who'] . ' ' $post['username'] . ' | ' $post['time'] .'</small>
 </td>
 </tr>
 </table>'
;



echo 
'</div><br />';
 }

//Scrolling xD
if ($scrolling == 1)
echo 
'</marquee></div>';
 ?>

portal.css;

Code: [Select]
.mansetdeneme
{
    align: left;
   border: 1px solid #5998A7;
   border-radius: 3px;
   -moz-border-radius: 3px;
   -webkit-border-radius: 3px;
  padding: 3px 5px 7px 5px;  ;  üst sağ alt Sol
}
.manseta
{
   align: left;
   border: 1px solid #5998A7;
   border-radius: 3px;
   -moz-border-radius: 3px;
   -webkit-border-radius: 3px;
  padding: 3px 5px 7px 5px;  ;  üst sağ alt Sol
margin-top: 0px;
}
.mansetg
{
width: 20px;
height: 20px;
}

Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: boo2 on September 19, 2012, 06:21:25 PM
Not sure anyone has noticed this but I opened my home page and found the this block wider than it should have been, by almost twice. So I noted the very lost post I mad and I had instructions inside the [ code ] tags, and when i opened that post and removed the code tags the block went back to it's normal size. How odd. Can anyone tell me if this code is causing that?

Must be because when I remove the code tags from that post all was well again.

I wonder if it's possible to have all urls and video urls removed so that they don't make the block look messy when you have the post content in view? I'd hate to miss out on the preview of the comments in the post but the urls look awful in the block.

Here's the code I am using with some modifications to it i found in this thread.
Code: [Select]
<?php

/*
Block: Recent posts with post preview
Author: Blue @ Simple Portal.net
Version: 1.5
*/

/* [SETUP WHAT YOU WANT HERE] */

$topics_posts 1; // TOPICS - 1 | MESSAGES - 2
$limit 15; // How many recent posts do you want to output?
$number 140; // How many characters do you want to output?
$exclude_boards = array( 12); // IF null guests can see all boards | IF you want to hide some boards use: array( ID1, ID2, ID3) where ID is the board's ID
$default_avatar 'http://cafewe.com/Themes/default/images/default_avatar.png';
$htmlspecialcharacters false// Do you need to show html special characters like Greek characters?

// Scroll Enable? Height and Speed?
$scrolling 2;       // ENABLE - 1 | DISABLE - 2
$height "400px";
$speed 3;           // SLOW - 1 | MEDIUM - 10 | FAST - 20

// Do you want to translate it to your own language? :P
$text['sportal_false'] = 'Simple Portal not found';
$text['board'] = '';
$text['who'] = '';

/* [STOP!] - THIS IS THE END OF SETUP */

//Only code from now on ;)
global $smcFunc$scripturl$sourcedir$modSettings$user_info$settings$context;

// Lets see if you are using Simple Portal. If not...well...go get them :D
if (!file_exists($sourcedir '/PortalBlocks.php'))
{
echo $text['sportal_false'];
return;
}

// Let's grab some database results
if ($topics_posts == 1) {

if (is_array($exclude_boards) || (int) $exclude_boards === $exclude_boards)
{
$exclude_boards is_array($exclude_boards) ? $exclude_boards : array($exclude_boards);
}
elseif ($exclude_boards != null)
{
$output_method $exclude_boards;
$exclude_boards = array(ID20ID21ID22ID23ID24ID25);
}

$posts_result $smcFunc['db_query']('''
   SELECT IFNULL(u.real_name, m.poster_name) AS poster_name, m.poster_time, m.id_msg, t.id_member_updated, m.subject, m.body, m.id_topic, b.name, t.id_last_msg, u.avatar, g.online_color,' 
. ($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'
) . '
   FROM {db_prefix}topics AS t
   LEFT JOIN {db_prefix}boards AS b ON (t.id_board = b.id_board)
   LEFT JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_last_msg)
   LEFT JOIN {db_prefix}members AS u ON (t.id_member_updated = u.id_member)
   LEFT JOIN {db_prefix}membergroups AS g ON (g.id_group = CASE WHEN u.id_group = 0 THEN u.id_post_group ELSE u.id_group END)
   ' 
. (!$user_info['is_guest'] ? '
LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = m.id_topic AND lt.id_member = ' 
$user_info['id'] . ')
LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = b.id_board AND lmr.id_member = ' 
$user_info['id'] . ')' '') . '     
   WHERE m.approved=1'   
. (empty($exclude_boards) ? '' '
AND b.id_board NOT IN ({array_int:exclude_boards})'
) . ' AND {query_see_board}
   ORDER BY t.id_last_msg DESC
   LIMIT ' 
$limit
array(
'exclude_boards' => empty($exclude_boards) ? '' $exclude_boards,
)   
   );
$posts = array();
while (
$row_posts $smcFunc['db_fetch_assoc']($posts_result))
{

      global 
$memberContext;
      
loadMemberData($row_posts['id_member_updated']);
      
loadMemberContext($row_posts['id_member_updated']);

   
$posts[] = array(
  'id' => $row_posts['id_member_updated'],
      
'username' => '<a style="color: ' $row_posts['online_color'] . ';" href="' $scripturl '?action=profile;u=' $row_posts['id_member_updated'] . '">' $row_posts['poster_name'] . '</a>',
      
'subject' => '<a style="font-weight: bold;" title="' $text['board'] . '&nbsp;' $row_posts['name'] .'" href="' $scripturl '?topic=' $row_posts['id_topic'] . '.msg' $row_posts['id_last_msg'] . ';topicseen#new">' $row_posts['subject'] . '</a>',
      
'body' => $row_posts['body'],
  'avatar' => $row_posts['avatar'] == '' $memberContext[$row_posts['id_member_updated']]['avatar']['href'] : (stristr($row_posts['avatar'], 'http://') ? $row_posts['avatar'] : $modSettings['avatar_url'] . '/' $row_posts['avatar']),
  'board' => $row_posts['name'], 
  'time' => timeformat($row_posts['poster_time']),
  'new' => !empty($row_posts['is_read'])
   );
}
$smcFunc['db_free_result']($posts_result);

} else {

if (is_array($exclude_boards) || (int) $exclude_boards === $exclude_boards)
{
$exclude_boards is_array($exclude_boards) ? $exclude_boards : array($exclude_boards);
}
elseif ($exclude_boards != null)
{
$output_method $exclude_boards;
$exclude_boards = array();
}

$posts_result $smcFunc['db_query']('''
   SELECT IFNULL(u.real_name, m.poster_name) AS poster_name, m.poster_time, m.id_msg, m.id_member, m.subject, m.body, m.id_topic, b.name, b.id_board, u.avatar, g.online_color,' 
. ($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'
) . '
   FROM {db_prefix}messages AS m
   LEFT JOIN {db_prefix}boards AS b ON (m.id_board = b.id_board)
   LEFT JOIN {db_prefix}members AS u ON (m.id_member = u.id_member)
   LEFT JOIN {db_prefix}membergroups AS g ON (g.id_group = CASE WHEN u.id_group = 0 THEN u.id_post_group ELSE u.id_group END)
   ' 
. (!$user_info['is_guest'] ? '
LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = m.id_topic AND lt.id_member = ' 
$user_info['id'] . ')
LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = b.id_board AND lmr.id_member = ' 
$user_info['id'] . ')' '') . '   
   WHERE m.approved=1'   
. (empty($exclude_boards) ? '' '
AND b.id_board NOT IN ({array_int:exclude_boards})'
) . ' AND {query_see_board}
   ORDER BY m.id_msg DESC
   LIMIT ' 
$limit
array(
'exclude_boards' => empty($exclude_boards) ? '' $exclude_boards,
)   
   );
$posts = array();
while (
$row_posts $smcFunc['db_fetch_assoc']($posts_result))
{

      global 
$memberContext;
      
loadMemberData($row_posts['id_member']);
      
loadMemberContext($row_posts['id_member']);

   
$posts[] = array(
  'id' => $row_posts['id_member'],
      
'username' => '<a style="color: ' $row_posts['online_color'] . ';" href="' $scripturl '?action=profile;u=' $row_posts['id_member'] . '">' $row_posts['poster_name'] . '</a>',
      
'subject' => '<a style="font-weight: bold;" title="' $text['board'] . '&nbsp;' $row_posts['name'] .'" href="' $scripturl '?topic=' $row_posts['id_topic'] . '.msg' $row_posts['id_msg'] . ';topicseen#new">' $row_posts['subject'] . '</a>',
      
'body' => $row_posts['body'],
  'avatar' => $row_posts['avatar'] == '' $memberContext[$row_posts['id_member']]['avatar']['href'] : (stristr($row_posts['avatar'], 'http://') ? $row_posts['avatar'] : $modSettings['avatar_url'] . '/' $row_posts['avatar']),
  'board' => $row_posts['name'],  
  'time' => timeformat($row_posts['poster_time']),
  'new' => !empty($row_posts['is_read'])
   );
}
$smcFunc['db_free_result']($posts_result);

}

//Finally the Output

//Scrolling xD
if ($scrolling == 1)
echo 
'<div style="overflow: hidden;"><marquee height=' $height ' behavior="scroll" direction="up" scrollamount="' $speed '" onmouseover="this.stop()" onmouseout="this.start()">';

foreach (
$posts as $post) {

// Lets fix the BBCode bug and Strip the Text
$form_message preg_replace(array('~\n?\[quote.*?\].*\[/quote\]\n?~is''~^\n~''~\[/quote\]~'), ''$post['body']);
$content1 str_replace("[""<"$form_message);
$content2 str_replace("]"">"$content1); 
$content3 strip_tags($content2);
$preview strip_tags(substr (htmlspecialchars_decode($content3),0,$number));

echo
'<table>
<tr>'
;
if (!(empty(
$post['avatar'])))
echo
'    <td style="width: 40px;">';

if (!empty($post['avatar'])){
echo '<img src="' $post['avatar'] .'" alt="" width="40px" height="40px" />';
} else {
echo '<img src="' $default_avatar .'" alt="" width="40px" height="40px" />';
}
echo '  </td><td>
str_ireplace('Re: '''$post['subject']);

if (!$post['new'] && $context['user']['is_logged'])
echo '&nbsp;<img src="'$settings['images_url'], '/'$context['user']['language'], '/new.gif" alt="new" border="0" />';

echo '<br />
<small>' 
$text['who'] . '&nbsp;' $post['username'] . '&nbsp;|&nbsp;' $post['time'] .'</small>
</td>
</tr>
</table>'
;

if ($htmlspecialcharacters) {
echo htmlspecialchars($previewENT_NOQUOTES"UTF-8") . '...';
} else {
echo $preview '...';
}

echo 
'<hr />';
}

//Scrolling xD
if ($scrolling == 1)
echo 
'</marquee></div>';
?>
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: velorooms on October 07, 2012, 10:37:29 AM
is it possible to edit it so that when scrolling and it reaches the bottom the new posts it doesnt insert the whitespace so that there is a constant flow of posts rather than a gap between last and first?
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: Xarwin on November 04, 2012, 06:40:04 PM
I just wanted to thank you for this amazing piece of coding.
Works flawlessly.
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: kachan64 on November 09, 2012, 11:43:05 PM
Got so much boards.
How can I exclude them easily?  :0
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: Blue on November 11, 2012, 01:42:01 PM
Got so much boards.
How can I exclude them easily?  :0

You can exclude some boards changing the value

Code: [Select]
$exclude_boards = null;
See the info in the first post ;)

I just wanted to thank you for this amazing piece of coding.
Works flawlessly.

Thank you :D :D
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: FrizzleFried on November 14, 2012, 10:46:03 AM
Looking at the screenshot below...

How do I make the "box" for Recent Topics a specific size ... like when set for scrolling... yet NOT scroll... but rather have a slider?

Thanks!

Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: Tricky on November 16, 2012, 04:51:15 AM
Fantastic thanks for this
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: dhayzon on November 18, 2012, 05:37:32 PM
Thanks for this block

(http://i.imgur.com/bSbDr.png)
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: Blue on November 19, 2012, 02:44:27 PM
Fantastic thanks for this
Thanks for this block

Glad you liked it :D
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: FrizzleFried on November 19, 2012, 07:33:57 PM
Looking at the screenshot below...

How do I make the "box" for Recent Topics a specific size ... like when set for scrolling... yet NOT scroll... but rather have a slider?

Thanks!

Still wondering how I can make it stop scrolling ... but include a scroll bar instead?

Thanks!
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: Blue on November 24, 2012, 08:09:09 PM
Hum... Scroll bar, no auto scrolling right? :) I'll code it for you tomorrow
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: FrizzleFried on November 24, 2012, 10:02:13 PM
Hum... Scroll bar, no auto scrolling right? :) I'll code it for you tomorrow

Correct...

:)

Thank you sir!

Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: Blue on November 25, 2012, 08:35:34 PM
Block updated :D Version 1.6 (see first post)

Added the possibility to show the vertical scrollbar with the height that you want ;)
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: FrizzleFried on November 26, 2012, 01:52:39 PM
Thank you!

Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: Blue on November 26, 2012, 06:36:08 PM
Thank you!

Glad I could be of help :)
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: Ahmad Rasyid Ismail on December 19, 2012, 12:17:21 AM
A very very nice mod.
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: Mick. on December 26, 2012, 07:37:16 PM
Yup. One of my favorite blocks ;)
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: Mick. on January 01, 2013, 11:21:17 AM
One thing i found is, when posting an image url inside the image tags, the image url shows on the block.  FYI.
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: kimyaci on January 01, 2013, 08:32:06 PM
Hi Blue
Thank you very much for this block.But it does not look good links.Only text seem more beautiful.

(http://img15.hostingpics.net/pics/412233ScreenShot072.png) (http://www.hostingpics.net/viewer.php?id=412233ScreenShot072.png)
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: dhayzon on January 09, 2013, 10:25:26 AM
I'm playing a little
but how would it?
(http://i.imgur.com/6TFQg.png)



Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: Blue on January 13, 2013, 09:52:08 PM
One thing i found is, when posting an image url inside the image tags, the image url shows on the block.  FYI.

Thank you for the feedback, I'll fix it :)
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: teos on January 18, 2013, 06:55:24 AM
The block is great, I love it .

A small request ...

  Smiley's are displayed as text rather then the smiley itself and also &nbsp

Missing something ?
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: MissyNL on February 21, 2013, 02:13:57 PM
as many others... love the block :D

But after putting it online,  i noticed that my shoutbox did not work anymore. When i tried to delete the block or deactivate it i got this message: Session verification failed. Please try logging out and back in again, and then try again.

So.. i erased the php code... saved it and then was able to delete the block. very strange... has anyone also have this?


Have two suggestions though... is it possible to choose what boards to display? I have several categories in recent topics since my forum is quit large. So it would be very handy for me to choose what topics are displayd... also...

Is it possible to align the avatar in the top left with a small V & hspace? Now the avatar shows in the middle and it looks messy...

Also... Although i have selected to show the topics... it shows the RE: before it... can that also be deleted?
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: thisizaremix on March 02, 2013, 03:48:35 AM
After searching and searching for days and not finding a "Recent Posts" block that links to the beginning of a topic along with linking to the last post, I modified your code successfully to get it to do what I want.  I don't write code, I just try to modify it to get it to work the way I want.

It works perfectly but it still has a bunch of code that isn't necessary for what I am using it for.  Could you please help me clean it up to get rid of the stuff I am not using?

Here is a screenshot of how I am using this:
(http://s17.postimage.org/s5e5ktoov/Screen_Hunter_75_Mar_02_01_46.jpg)

Code: [Select]
<?php

/*
Block: Recent posts with post preview
Author: Blue @ Simple Portal.net
Version: 1.6
*/

/* [SETUP WHAT YOU WANT HERE] */

$topics_posts 1; // TOPICS - 1 | MESSAGES - 2
$limit 10; // How many recent posts do you want to output?
$number 0; // How many characters do you want to output?
$exclude_boards null; // IF null guests can see all boards | IF you want to hide some boards use: array( ID1, ID2, ID3) where ID is the board's ID
$htmlspecialcharacters false// Do you need to show html special characters like Greek characters?

// Scroll Enable? Height and Speed?
$scrolling 0;       // ENABLE - 1 | DISABLE - 2
$speed 3;           // SLOW - 1 | MEDIUM - 10 | FAST - 20
$height "150px";
$scrollbar 0;       // ENABLE - 1 | DISABLE - 2

// Do you want to translate it to your own language? :P
$text['sportal_false'] = 'Simple Portal not found';
$text['board'] = 'in';
$text['who'] = 'by';

/* [STOP!] - THIS IS THE END OF SETUP */

//Only code from now on ;)
global $smcFunc$scripturl$sourcedir$modSettings$user_info$settings$context;

// Lets see if you are using Simple Portal. If not...well...go get them :D
if (!file_exists($sourcedir '/PortalBlocks.php'))
{
echo $text['sportal_false'];
return;
}

// Let's grab some database results
if ($topics_posts == 1) {

if (is_array($exclude_boards) || (int) $exclude_boards === $exclude_boards)
{
$exclude_boards is_array($exclude_boards) ? $exclude_boards : array($exclude_boards);
}
elseif ($exclude_boards != null)
{
$output_method $exclude_boards;
$exclude_boards = array();
}

$posts_result $smcFunc['db_query']('''
   SELECT m.poster_name, m.poster_time, m.id_msg, t.id_member_updated, m.subject, m.body, m.id_topic, b.name, t.id_last_msg, u.avatar, g.online_color,' 
. ($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'
) . '
   FROM {db_prefix}topics AS t
   LEFT JOIN {db_prefix}boards AS b ON (t.id_board = b.id_board)
   LEFT JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_last_msg)
   LEFT JOIN {db_prefix}members AS u ON (t.id_member_updated = u.id_member)
   LEFT JOIN {db_prefix}membergroups AS g ON (g.id_group = CASE WHEN u.id_group = 0 THEN u.id_post_group ELSE u.id_group END)
   ' 
. (!$user_info['is_guest'] ? '
LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = m.id_topic AND lt.id_member = ' 
$user_info['id'] . ')
LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = b.id_board AND lmr.id_member = ' 
$user_info['id'] . ')' '') . '     
   WHERE m.approved=1'   
. (empty($exclude_boards) ? '' '
AND b.id_board NOT IN ({array_int:exclude_boards})'
) . ' AND {query_see_board}
   ORDER BY t.id_last_msg DESC
   LIMIT ' 
$limit
array(
'exclude_boards' => empty($exclude_boards) ? '' $exclude_boards,
)   
   );
$posts = array();
while (
$row_posts $smcFunc['db_fetch_assoc']($posts_result))
{

      global 
$memberContext;
      
loadMemberData($row_posts['id_member_updated']);
      
loadMemberContext($row_posts['id_member_updated']);

   
$posts[] = array(
  'id' => $row_posts['id_member_updated'],
      
'username' => '<a style="color: ' $row_posts['online_color'] . ';" href="' $scripturl '?action=profile;u=' $row_posts['id_member_updated'] . '">' $row_posts['poster_name'] . '</a>',
      
'subject' => '<a style="font-weight: bold;" title="' $row_posts['subject'] . '" href="' $scripturl '?topic=' $row_posts['id_topic'] . ';topicseen#new">' $row_posts['subject'] . '</a>',
      
'subject2' => '<a style="color:red;"font-weight: bold;" title="Go to the last post" href="' $scripturl '?topic=' $row_posts['id_topic'] . '.msg' $row_posts['id_last_msg'] . ';topicseen#new">&#38;#9658;Last Post</a>',
      
'body' => $row_posts['body'],
  'avatar' => $row_posts['avatar'] == '' $memberContext[$row_posts['id_member_updated']]['avatar']['href'] : (stristr($row_posts['avatar'], 'http://') ? $row_posts['avatar'] : $modSettings['avatar_url'] . '/' $row_posts['avatar']),
  'board' => $row_posts['name'], 
  'time' => timeformat($row_posts['poster_time']),
  'new' => !empty($row_posts['is_read'])
   );
}
$smcFunc['db_free_result']($posts_result);

} else {

if (is_array($exclude_boards) || (int) $exclude_boards === $exclude_boards)
{
$exclude_boards is_array($exclude_boards) ? $exclude_boards : array($exclude_boards);
}
elseif ($exclude_boards != null)
{
$output_method $exclude_boards;
$exclude_boards = array();
}

$posts_result $smcFunc['db_query']('''
   SELECT m.poster_name, m.poster_time, m.id_msg, m.id_member, m.subject, m.body, m.id_topic, b.name, b.id_board, u.avatar, g.online_color,' 
. ($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'
) . '
   FROM {db_prefix}messages AS m
   LEFT JOIN {db_prefix}boards AS b ON (m.id_board = b.id_board)
   LEFT JOIN {db_prefix}members AS u ON (m.id_member = u.id_member)
   LEFT JOIN {db_prefix}membergroups AS g ON (g.id_group = CASE WHEN u.id_group = 0 THEN u.id_post_group ELSE u.id_group END)
   ' 
. (!$user_info['is_guest'] ? '
LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = m.id_topic AND lt.id_member = ' 
$user_info['id'] . ')
LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = b.id_board AND lmr.id_member = ' 
$user_info['id'] . ')' '') . '   
   WHERE m.approved=1'   
. (empty($exclude_boards) ? '' '
AND b.id_board NOT IN ({array_int:exclude_boards})'
) . ' AND {query_see_board}
   ORDER BY m.id_msg DESC
   LIMIT ' 
$limit
array(
'exclude_boards' => empty($exclude_boards) ? '' $exclude_boards,
)   
   );
$posts = array();
while (
$row_posts $smcFunc['db_fetch_assoc']($posts_result))
{

      global 
$memberContext;
      
loadMemberData($row_posts['id_member']);
      
loadMemberContext($row_posts['id_member']);

   
$posts[] = array(
  'id' => $row_posts['id_member'],
      
'username' => '<a style="color: ' $row_posts['online_color'] . ';" href="' $scripturl '?action=profile;u=' $row_posts['id_member'] . '">' $row_posts['poster_name'] . '</a>',
      
'subject' => '<a style="font-weight: bold;" title="' $text['board'] . '&nbsp;' $row_posts['name'] .'" href="' $scripturl '?topic=' $row_posts['id_topic'] . '.msg' $row_posts['id_msg'] . ';topicseen#new">' $row_posts['subject'] . '</a>',
      
'body' => $row_posts['body'],
  'avatar' => $row_posts['avatar'] == '' $memberContext[$row_posts['id_member']]['avatar']['href'] : (stristr($row_posts['avatar'], 'http://') ? $row_posts['avatar'] : $modSettings['avatar_url'] . '/' $row_posts['avatar']),
  'board' => $row_posts['name'],  
  'time' => timeformat($row_posts['poster_time']),
  'new' => !empty($row_posts['is_read'])
   );
}
$smcFunc['db_free_result']($posts_result);

}

//Finally the Output

//Scrolling xD
if ($scrolling == 1)
echo 
'<div style="overflow: hidden;"><marquee height=' $height ' behavior="scroll" direction="up" scrollamount="' $speed '" onmouseover="this.stop()" onmouseout="this.start()">';

if (
$scrollbar == 1)
echo 
'<div style="height:' $height '; overflow-y: scroll; overflow-x: hidden;">';

foreach (
$posts as $post) {

// Lets fix the BBCode bug and Strip the Text
$content1 str_replace("[""<"$post['body']);
$content2 str_replace("]"">"$content1); 
$content3 strip_tags($content2);
$preview substr ($content3,0,$number);

echo
'<table>
<tr>

<td>
str_ireplace('Re: '''$post['subject']);

if (!$post['new'] && $context['user']['is_logged'])
echo '&nbsp;<img src="'$settings['images_url'], '/'$context['user']['language'], '/new.gif" alt="new" border="0" />';

echo
'



<br /><small>' 
$post['subject2'];




echo '
$text['who'] . '&nbsp;' $post['username'] . '<br />' $post['time'] .'</small>
</td>
</tr>
</table>'
;

if ($htmlspecialcharacters) {
echo htmlspecialchars($previewENT_NOQUOTES"UTF-8") . '';
} else {
echo $preview '';
}

echo 
'<hr />';
}
        
//Scrolling xD
if ($scrollbar == 1)
echo 
'</div>'

if (
$scrolling == 1)
echo 
'</marquee></div>';
?>
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: t-geronimo on March 17, 2013, 10:56:11 AM
Hello!

I am new here and "search" did not help me.

Is there any way to exclude not only boards from the "Recent Topics/Posts"-block but also subboards?
Sorry if this was already asked and I did not find it.
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: velorooms on March 25, 2013, 05:31:10 PM
Im wondering how easy it would be to work it so that it only pulls the latest posts from the topic it is in.

For instance, one block, but when displayed in board 72 it only pulls topics from board 72, etc

So it displays latest posts from the currently active board?
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: Old Fossil on April 08, 2013, 10:06:17 PM
Tried this on my forum.

However I am unable to hide more than one board despite having a few I want to remain hidden.

Any fix?

Have been seeing erors in my error log regarding this.

Use of undefined constant ID2 - assumed 'ID2'
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: Blue on April 27, 2013, 08:28:01 AM
Hello!

I am new here and "search" did not help me.

Is there any way to exclude not only boards from the "Recent Topics/Posts"-block but also subboards?
Sorry if this was already asked and I did not find it.
Subboards have their own ID so just add it to the excluded_boards parameter :)
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: Blue on May 02, 2013, 08:22:03 PM
Tried this on my forum.

However I am unable to hide more than one board despite having a few I want to remain hidden.

Any fix?

Have been seeing erors in my error log regarding this.

Use of undefined constant ID2 - assumed 'ID2'

Hum... it is working on my test forum. Can you please show me the code that you are using? I want to see the excluded_boards parameter

Im wondering how easy it would be to work it so that it only pulls the latest posts from the topic it is in.

For instance, one block, but when displayed in board 72 it only pulls topics from board 72, etc

So it displays latest posts from the currently active board?

It's a great idea, I'm going to look it it and add it in the next version :)
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: Old Fossil on May 02, 2013, 08:28:31 PM
Code: [Select]
/*
Block: Recent posts with post preview
Author: Blue @ Simple Portal.net
Version: 1.6
*/

/* [SETUP WHAT YOU WANT HERE] */

$topics_posts = 1; // TOPICS - 1 | MESSAGES - 2
$limit = 10; // How many recent posts do you want to output?
$number = 70; // How many characters do you want to output?
$exclude_boards = ( 2 ); // IF null guests can see all boards | IF you want to hide some boards use: array( ID1, ID2, ID3) where ID is the board's ID
$htmlspecialcharacters = false; // Do you need to show html special characters like Greek characters?

// Scroll Enable? Height and Speed?
$scrolling =1;       // ENABLE - 1 | DISABLE - 2
$speed = 2;           // SLOW - 1 | MEDIUM - 10 | FAST - 20
$height = "200px";
$scrollbar = 0;       // ENABLE - 1 | DISABLE - 2

// Do you want to translate it to your own language? :P
$text['sportal_false'] = 'Simple Portal not found';
$text['board'] = 'in';
$text['who'] = 'by';

/* [STOP!] - THIS IS THE END OF SETUP */

//Only code from now on ;)
global $smcFunc, $scripturl, $sourcedir, $modSettings, $user_info, $settings, $context, $memberContext;

// Lets see if you are using Simple Portal. If not...well...go get them :D
if (!file_exists($sourcedir . '/PortalBlocks.php'))
{
echo $text['sportal_false'];
return;
}

// Let's grab some database results
if ($topics_posts == 1)
{

    if (is_array($exclude_boards) || (int) $exclude_boards === $exclude_boards)
    $exclude_boards = is_array($exclude_boards) ? $exclude_boards : array($exclude_boards);
    elseif ($exclude_boards != null)
    {
$output_method = $exclude_boards;
$exclude_boards = array();
    }

    $posts_result = $smcFunc['db_query']('', '
      SELECT m.poster_name, m.poster_time, m.id_msg, t.id_member_updated, m.subject, m.body, m.id_topic, b.name,
    t.id_last_msg, u.avatar, g.online_color,' . ($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') . '
FROM {db_prefix}topics AS t
LEFT JOIN {db_prefix}boards AS b ON (t.id_board = b.id_board)
LEFT JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_last_msg)
LEFT JOIN {db_prefix}members AS u ON (t.id_member_updated = u.id_member)
LEFT JOIN {db_prefix}membergroups AS g ON (g.id_group = CASE WHEN u.id_group = 0 THEN u.id_post_group ELSE u.id_group END)
' . (!$user_info['is_guest'] ? '
LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = m.id_topic AND lt.id_member = ' . $user_info['id'] . ')
LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = b.id_board AND lmr.id_member = ' . $user_info['id'] . ')' : '') . '     
WHERE m.approved=1'   . (empty($exclude_boards) ? '' : ' AND m.poster_time > 0
AND b.id_board NOT IN ({array_int:exclude_boards})') . ' AND {query_see_board}
ORDER BY t.id_last_msg DESC
LIMIT ' . $limit,
array('exclude_boards' => empty($exclude_boards) ? '' : $exclude_boards,)   
);
    $posts = array();
    while ($row_posts = $smcFunc['db_fetch_assoc']($posts_result))
    {
loadMemberData($row_posts['id_member_updated']);
loadMemberContext($row_posts['id_member_updated']);

$posts[] = array(
    'id' => $row_posts['id_member_updated'],
    'username' => '<a style="color: ' . $row_posts['online_color'] . ';" href="' . $scripturl . '?action=profile;u=' . $row_posts['id_member_updated'] . '">' . $row_posts['poster_name'] . '</a>',
    'subject' => '<a style="font-weight: bold;" title="' . $text['board'] . '&nbsp;' . $row_posts['name'] .'" href="' . $scripturl . '?topic=' . $row_posts['id_topic'] . '.msg' . $row_posts['id_last_msg'] . ';topicseen#new">' . $row_posts['subject'] . '</a>',
    'body' => $row_posts['body'],
    'avatar' => $row_posts['avatar'] == '' ? $memberContext[$row_posts['id_member_updated']]['avatar']['href'] : (stristr($row_posts['avatar'], 'http://') ? $row_posts['avatar'] : $modSettings['avatar_url'] . '/' . $row_posts['avatar']),
    'board' => $row_posts['name'],
    'time' => timeformat($row_posts['poster_time']),
    'new' => !empty($row_posts['is_read'])
        );
    }
    $smcFunc['db_free_result']($posts_result);

}
else
{
    if (is_array($exclude_boards) || (int) $exclude_boards === $exclude_boards)
$exclude_boards = is_array($exclude_boards) ? $exclude_boards : array($exclude_boards);
    elseif ($exclude_boards != null)
    {
$output_method = $exclude_boards;
$exclude_boards = array();
    }

    $posts_result = $smcFunc['db_query']('', '
SELECT m.poster_name, m.poster_time, m.id_msg, m.id_member, m.subject, m.body, m.id_topic, b.name,
b.id_board, u.avatar, g.online_color,' . ($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') . '
FROM {db_prefix}messages AS m
LEFT JOIN {db_prefix}boards AS b ON (m.id_board = b.id_board)
LEFT JOIN {db_prefix}members AS u ON (m.id_member = u.id_member)
LEFT JOIN {db_prefix}membergroups AS g ON (g.id_group = CASE WHEN u.id_group = 0 THEN u.id_post_group ELSE u.id_group END)
' . (!$user_info['is_guest'] ? '
LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = m.id_topic AND lt.id_member = ' . $user_info['id'] . ')
LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = b.id_board AND lmr.id_member = ' . $user_info['id'] . ')' : '') . '   
WHERE m.approved=1'   . (empty($exclude_boards) ? '' : ' AND m.poster_time > 0
AND b.id_board NOT IN ({array_int:exclude_boards})') . ' AND {query_see_board}
ORDER BY m.id_msg DESC
LIMIT ' . $limit,
array('exclude_boards' => empty($exclude_boards) ? '' : $exclude_boards,)   
    );
    $posts = array();
    while ($row_posts = $smcFunc['db_fetch_assoc']($posts_result))
    {
loadMemberData($row_posts['id_member']);
loadMemberContext($row_posts['id_member']);

$posts[] = array(
    'id' => $row_posts['id_member'],
    'username' => '<a style="color: ' . $row_posts['online_color'] . ';" href="' . $scripturl . '?action=profile;u=' . $row_posts['id_member'] . '">' . $row_posts['poster_name'] . '</a>',
    'subject' => '<a style="font-weight: bold;" title="' . $text['board'] . '&nbsp;' . $row_posts['name'] .'" href="' . $scripturl . '?topic=' . $row_posts['id_topic'] . '.msg' . $row_posts['id_msg'] . ';topicseen#new">' . $row_posts['subject'] . '</a>',
    'body' => $row_posts['body'],
    'avatar' => $row_posts['avatar'] == '' ? $memberContext[$row_posts['id_member']]['avatar']['href'] : (stristr($row_posts['avatar'], 'http://') ? $row_posts['avatar'] : $modSettings['avatar_url'] . '/' . $row_posts['avatar']),
    'board' => $row_posts['name'], 
    'time' => timeformat($row_posts['poster_time']),
    'new' => !empty($row_posts['is_read'])
    );
    }
    $smcFunc['db_free_result']($posts_result);
}

//Finally the Output

//Scrolling xD
if ($scrolling == 1)
    echo '
    <marquee style="overflow:hidden;height:' . $height . ';" behavior="scroll" direction="up" scrollamount="' . $speed . '" onmouseover="this.stop()" onmouseout="this.start()">';

if ($scrollbar == 1 && !empty($posts))
    echo '
<div style="height:' . $height . '; overflow-y: scroll; overflow-x: hidden;">';

if (!empty($posts))
    echo '
    <table style="width:100%;">';
   
foreach ($posts as $post)
{
    if (empty($post['body']))
    {
echo '<tr><td>&nbsp</td></tr>';
exit;
    }
   
    // Lets fix the BBCode bug and Strip the Text
    $content1 = str_replace("[", "<", $post['body']);
    $content2 = str_replace("]", ">", $content1);
    $content3 = strip_tags($content2);
    $preview = substr($content3,0,$number);

    echo'    
<tr>
    <td style="width: 40px;">
<img src="' . $post['avatar'] .'" alt="" style="width:40px;height:40px;position:relative;top:10px;" />
    </td>
    <td>
' . $post['subject'];

    if (!$post['new'] && $context['user']['is_logged'])
echo '
&nbsp;<img src="', $settings['images_url'], '/', $context['user']['language'], '/new.gif" alt="new" border="0" />';

echo '
<br />
<span style="font-size:small;">' . $text['who'] . '&nbsp;' . $post['username'] . '&nbsp;|&nbsp;' . $post['time'] .'</span>
    </td>
</tr>
<tr>';

    if ($htmlspecialcharacters)
echo '
    <td style="border:0px;">&nbsp;</td>
    <td style="border:0px;">', htmlspecialchars($preview, ENT_NOQUOTES, "UTF-8") . '...', '</td>';
    else
echo '
    <td style="border:0px;">&nbsp;</td>
    <td style="border:0px;">', $preview . '...', '</td>';

    echo '
</tr>
<tr>
    <td colspan="2" style="border-top: thin dotted;height:0px;line-height:0px;padding:0%;display:hidden;width:100%;position:relative;">
<span></span>
    </td>
</tr>';
}

if (!empty($posts))
    echo '
    </table>';
   
//Scrolling xD
if ($scrollbar == 1 && !empty($posts))
    echo '
</div>';

if ($scrolling == 1)
    echo '
    </marquee>';

Here ya go Blue (or is it Purple?)

Anyways can ya show me where exactly the board numbers should go please bud.

Another thing I recently noticed.

Is there a way for the block to show the display name and not the name a person registered with?

Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: Mick. on May 02, 2013, 11:29:22 PM
Blue, if or when you update, remember img tags are shown in the preview as bbc. I think code tags too but I don't remember.
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: Blue on May 04, 2013, 07:48:56 AM
Here ya go Blue (or is it Purple?)

It is Blue but SiNaN prefers to call me Purple :dead: eheh!

Quote
Anyways can ya show me where exactly the board numbers should go please bud.

Another thing I recently noticed.

Is there a way for the block to show the display name and not the name a person registered with?

In the excluded parameter you forgot to add "array()". If you want to excluded more than one board you have to write "array( ID1, ID2, ID3)"

I have made the modifications so that it displays the real_name instead of poster_name :) try and see if everything is alright

Code: [Select]
<?php
/*
Block: Recent posts with post preview
Author: Blue @ Simple Portal.net
Version: 1.6
*/

/* [SETUP WHAT YOU WANT HERE] */

$topics_posts 1; // TOPICS - 1 | MESSAGES - 2
$limit 10; // How many recent posts do you want to output?
$number 70; // How many characters do you want to output?
$exclude_boards = array(2); // IF null guests can see all boards | IF you want to hide some boards use: array( ID1, ID2, ID3) where ID is the board's ID
$htmlspecialcharacters false// Do you need to show html special characters like Greek characters?

// Scroll Enable? Height and Speed?
$scrolling =1;       // ENABLE - 1 | DISABLE - 2
$speed 2;           // SLOW - 1 | MEDIUM - 10 | FAST - 20
$height "200px";
$scrollbar 0;       // ENABLE - 1 | DISABLE - 2

// Do you want to translate it to your own language? :P
$text['sportal_false'] = 'Simple Portal not found';
$text['board'] = 'in';
$text['who'] = 'by';

/* [STOP!] - THIS IS THE END OF SETUP */

//Only code from now on ;)
global $smcFunc$scripturl$sourcedir$modSettings$user_info$settings$context$memberContext;

// Lets see if you are using Simple Portal. If not...well...go get them :D
if (!file_exists($sourcedir '/PortalBlocks.php'))
{
echo $text['sportal_false'];
return;
}

// Let's grab some database results
if ($topics_posts == 1)
{

    if (
is_array($exclude_boards) || (int) $exclude_boards === $exclude_boards)
    
$exclude_boards is_array($exclude_boards) ? $exclude_boards : array($exclude_boards);
    elseif (
$exclude_boards != null)
    {
$output_method $exclude_boards;
$exclude_boards = array();
    }

    
$posts_result $smcFunc['db_query']('''
      SELECT u.real_name, m.poster_time, m.id_msg, t.id_member_updated, m.subject, m.body, m.id_topic, b.name,
    t.id_last_msg, u.avatar, g.online_color,' 
. ($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'
) . '
FROM {db_prefix}topics AS t
LEFT JOIN {db_prefix}boards AS b ON (t.id_board = b.id_board)
LEFT JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_last_msg)
LEFT JOIN {db_prefix}members AS u ON (t.id_member_updated = u.id_member)
LEFT JOIN {db_prefix}membergroups AS g ON (g.id_group = CASE WHEN u.id_group = 0 THEN u.id_post_group ELSE u.id_group END)
. (!$user_info['is_guest'] ? '
LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = m.id_topic AND lt.id_member = ' 
$user_info['id'] . ')
LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = b.id_board AND lmr.id_member = ' 
$user_info['id'] . ')' '') . '     
WHERE m.approved=1'   
. (empty($exclude_boards) ? '' ' AND m.poster_time > 0
AND b.id_board NOT IN ({array_int:exclude_boards})'
) . ' AND {query_see_board}
ORDER BY t.id_last_msg DESC
LIMIT ' 
$limit
array('exclude_boards' => empty($exclude_boards) ? '' $exclude_boards,)   
);
    
$posts = array();
    while (
$row_posts $smcFunc['db_fetch_assoc']($posts_result))
    {

loadMemberData($row_posts['id_member_updated']);
loadMemberContext($row_posts['id_member_updated']);

$posts[] = array(
    'id' => $row_posts['id_member_updated'],
    'username' => '<a style="color: ' $row_posts['online_color'] . ';" href="' $scripturl '?action=profile;u=' $row_posts['id_member_updated'] . '">' $row_posts['real_name'] . '</a>',
    'subject' => '<a style="font-weight: bold;" title="' $text['board'] . '&nbsp;' $row_posts['name'] .'" href="' $scripturl '?topic=' $row_posts['id_topic'] . '.msg' $row_posts['id_last_msg'] . ';topicseen#new">' $row_posts['subject'] . '</a>',
    'body' => $row_posts['body'],
    'avatar' => $row_posts['avatar'] == '' $memberContext[$row_posts['id_member_updated']]['avatar']['href'] : (stristr($row_posts['avatar'], 'http://') ? $row_posts['avatar'] : $modSettings['avatar_url'] . '/' $row_posts['avatar']),
    'board' => $row_posts['name'], 
    'time' => timeformat($row_posts['poster_time']),
    'new' => !empty($row_posts['is_read'])
    
    );
    }
    
$smcFunc['db_free_result']($posts_result);

}
else
{
    if (
is_array($exclude_boards) || (int) $exclude_boards === $exclude_boards)
$exclude_boards is_array($exclude_boards) ? $exclude_boards : array($exclude_boards);
    elseif (
$exclude_boards != null)
    {
$output_method $exclude_boards;
$exclude_boards = array();
    }

    
$posts_result $smcFunc['db_query']('''
SELECT u.real_name, m.poster_time, m.id_msg, m.id_member, m.subject, m.body, m.id_topic, b.name,
b.id_board, u.avatar, g.online_color,' 
. ($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'
) . '
FROM {db_prefix}messages AS m
LEFT JOIN {db_prefix}boards AS b ON (m.id_board = b.id_board)
LEFT JOIN {db_prefix}members AS u ON (m.id_member = u.id_member)
LEFT JOIN {db_prefix}membergroups AS g ON (g.id_group = CASE WHEN u.id_group = 0 THEN u.id_post_group ELSE u.id_group END)
. (!$user_info['is_guest'] ? '
LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = m.id_topic AND lt.id_member = ' 
$user_info['id'] . ')
LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = b.id_board AND lmr.id_member = ' 
$user_info['id'] . ')' '') . '   
WHERE m.approved=1'   
. (empty($exclude_boards) ? '' ' AND m.poster_time > 0
AND b.id_board NOT IN ({array_int:exclude_boards})'
) . ' AND {query_see_board}
ORDER BY m.id_msg DESC
LIMIT ' 
$limit
array('exclude_boards' => empty($exclude_boards) ? '' $exclude_boards,)   
    );
    
$posts = array();
    while (
$row_posts $smcFunc['db_fetch_assoc']($posts_result))
    {

loadMemberData($row_posts['id_member']);
loadMemberContext($row_posts['id_member']);

$posts[] = array(
    'id' => $row_posts['id_member'],
    'username' => '<a style="color: ' $row_posts['online_color'] . ';" href="' $scripturl '?action=profile;u=' $row_posts['id_member'] . '">' $row_posts['real_name'] . '</a>',
    'subject' => '<a style="font-weight: bold;" title="' $text['board'] . '&nbsp;' $row_posts['name'] .'" href="' $scripturl '?topic=' $row_posts['id_topic'] . '.msg' $row_posts['id_msg'] . ';topicseen#new">' $row_posts['subject'] . '</a>',
    'body' => $row_posts['body'],
    'avatar' => $row_posts['avatar'] == '' $memberContext[$row_posts['id_member']]['avatar']['href'] : (stristr($row_posts['avatar'], 'http://') ? $row_posts['avatar'] : $modSettings['avatar_url'] . '/' $row_posts['avatar']),
    'board' => $row_posts['name'],  
    'time' => timeformat($row_posts['poster_time']),
    'new' => !empty($row_posts['is_read'])
    );
    }
    
$smcFunc['db_free_result']($posts_result);
}

//Finally the Output

//Scrolling xD
if ($scrolling == 1)
    echo 
'
    <marquee style="overflow:hidden;height:' 
$height ';" behavior="scroll" direction="up" scrollamount="' $speed '" onmouseover="this.stop()" onmouseout="this.start()">';

if (
$scrollbar == && !empty($posts))
    echo 
'
<div style="height:' 
$height '; overflow-y: scroll; overflow-x: hidden;">';

if (!empty(
$posts))
    echo 
'
    <table style="width:100%;">'
;
    
foreach (
$posts as $post)
{
    if (empty(
$post['body']))
    {
echo '<tr><td>&nbsp</td></tr>';
exit;
    }
    
    
// Lets fix the BBCode bug and Strip the Text
    
$content1 str_replace("[""<"$post['body']);
    
$content2 str_replace("]"">"$content1); 
    
$content3 strip_tags($content2);
    
$preview substr($content3,0,$number);

    echo
'     
<tr>
    <td style="width: 40px;">
<img src="' 
$post['avatar'] .'" alt="" style="width:40px;height:40px;position:relative;top:10px;" />
    </td>
    <td>
$post['subject'];

    if (!
$post['new'] && $context['user']['is_logged'])
echo '
&nbsp;<img src="'
$settings['images_url'], '/'$context['user']['language'], '/new.gif" alt="new" border="0" />';

echo '
<br />
<span style="font-size:small;">' 
$text['who'] . '&nbsp;' $post['username'] . '&nbsp;|&nbsp;' $post['time'] .'</span>
    </td>
</tr>
<tr>'
;

    if (
$htmlspecialcharacters
echo '
    <td style="border:0px;">&nbsp;</td>
    <td style="border:0px;">'
htmlspecialchars($previewENT_NOQUOTES"UTF-8") . '...''</td>';
    else 
echo '
    <td style="border:0px;">&nbsp;</td>
    <td style="border:0px;">'
$preview '...''</td>';

    echo 
'
</tr>
<tr>
    <td colspan="2" style="border-top: thin dotted;height:0px;line-height:0px;padding:0%;display:hidden;width:100%;position:relative;">
<span></span>
    </td>
</tr>'
;
}

if (!empty(
$posts))
    echo 
'
    </table>'
;
    
//Scrolling xD
if ($scrollbar == && !empty($posts))
    echo 
'
</div>'


if (
$scrolling == 1)
    echo 
'
    </marquee>'
;

Blue, if or when you update, remember img tags are shown in the preview as bbc. I think code tags too but I don't remember.

Thank you for the heads up. I'll fix it in the next version :)
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: Old Fossil on May 04, 2013, 11:03:58 AM
Excellent stuff Blue.

 :)

Looking forward to the next one already.
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: Vaughn on July 06, 2013, 05:52:43 AM
Excellent mod. Couple of questions (couldn't find any answers).

Can you get it to show emoticons instead of the text?
Can you get it to show Youtube vids instead of the link?
Can you automatically remove the "..." at the end if the message is already less characters than the max limit?
Can you add a reply button? (and/or a quick reply box which appears when you click "reply"?)
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: Old Fossil on July 06, 2013, 09:14:04 PM
Quote
Can you get it to show emoticons instead of the text?
Can you get it to show Youtube vids instead of the link?

If you read back through the topic the smileys will be changed so they do appear.

As for youtube these would be better as link texts not as an actual screen.
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: Blue on July 07, 2013, 08:33:22 AM
Can you automatically remove the "..." at the end if the message is already less characters than the max limit?
Can you add a reply button? (and/or a quick reply box which appears when you click "reply"?)

The 2 first questions Old Fossil answered as I would :)

These last ones are possible and I'll post back when done :)
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: Vaughn on July 07, 2013, 01:58:40 PM
I think the option to toggle videos on/off in the settings would be pretty handy. I know some people would prefer links as the videos take up screen space, but personally I'd prefer the videos to show.

I understand if that's too tough to code though. Or if I'm the only person who'd prefer it the other way.
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: Blue on July 07, 2013, 07:48:51 PM
I understand what you are saying and I'll see what I can do to help you :)
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: Old Fossil on July 07, 2013, 07:53:56 PM
/me is waiting.

Counting the years, months, weeks, days, hour, minutes and seconds.

 >:-D

Take ya time kiddo.
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: kimyaci on December 24, 2013, 02:20:19 PM
Quote from: Blue


guest name in the message color looks normal.However, the guest name colors in the topics appear different .

(http://img11.hostingpics.net/pics/383155ScreenShot007.jpg) (http://www.hostingpics.net/viewer.php?id=383155ScreenShot007.jpg)
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: Snoopix on December 29, 2013, 03:01:00 AM
how install this mod? only need copy code on php block?
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: Aquafan on December 29, 2013, 07:36:06 AM
realy nice but stil dont have the smiley's couldn't find any answer
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: Aquafan on January 05, 2014, 09:47:08 AM
any one?  :'(
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: kimyaci on January 06, 2014, 09:24:09 AM
1. Block:  do not to Active.
Code: [Select]
<?php

/*
Block: Recent posts with post preview
Author: Blue @ Simple Portal.net
Version: 1.5
*/

/* [SETUP WHAT YOU WANT HERE] */

$topics_posts 1;  // TOPICS - 1 | MESSAGES - 2
$limit 8;  // How many recent posts do you want to output?
$number 0;  // How many characters do you want to output?
$exclude_boards = array(318427426432425433424,423431434430,429,310);  // IF null guests can see all boards | IF you want to hide some boards use: array( ID1, ID2, ID3) where ID is the board's ID
$htmlspecialcharacters =true// Do you need to show html special characters like Greek characters?
$default_avatar 'http://img15.hostingpics.net/pics/282198defaultavatar.png';

// Scroll Enable? Height and Speed?
$scrolling 2;       // ENABLE - 1 | DISABLE - 2
$height "0px";
$speed 0;           // SLOW - 1 | MEDIUM - 10 | FAST - 20

// Do you want to translate it to your own language? :P
$text['sportal_false'] = 'Simple Portal not found';
$text['board'] = '';
$text['who'] = '';

/* [STOP!] - THIS IS THE END OF SETUP */

//Only code from now on ;)
global $smcFunc$scripturl$sourcedir$modSettings$user_info$settings$context;

// Lets see if you are using Simple Portal. If not...well...go get them :D
if (!file_exists($sourcedir '/PortalBlocks.php'))
{
 echo $text['sportal_false'];
 return;
}

// Let's grab some database results
if ($topics_posts == 1) {

 if (is_array($exclude_boards) || (int) $exclude_boards === $exclude_boards)
 {
 $exclude_boards is_array($exclude_boards) ? $exclude_boards : array($exclude_boards);
 }
 elseif ($exclude_boards != null)
 {
 $output_method $exclude_boards;
 $exclude_boards = array();
 }

$posts_result $smcFunc['db_query']('''
      SELECT m.poster_name, m.poster_time, m.id_msg, m.id_member, m.subject, m.body, m.id_topic, b.name, t.id_last_msg, u.avatar, g.online_color,' 
. ($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'
) . '
   FROM {db_prefix}topics AS t
   LEFT JOIN {db_prefix}boards AS b ON (t.id_board = b.id_board)
   LEFT JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_last_msg)
   LEFT JOIN {db_prefix}members AS u ON (m.id_member = u.id_member)
   LEFT JOIN {db_prefix}membergroups AS g ON (g.id_group = CASE WHEN u.id_group = 0 THEN u.id_post_group ELSE u.id_group END)
   ' 
. (!$user_info['is_guest'] ? '
 LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = m.id_topic AND lt.id_member = ' 
$user_info['id'] . ')
 LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = b.id_board AND lmr.id_member = ' 
$user_info['id'] . ')' '') . '     
   WHERE m.approved=1'   
. (empty($exclude_boards) ? '' '
 AND b.id_board NOT IN ({array_int:exclude_boards})'
) . ' AND {query_see_board}
   ORDER BY t.id_last_msg DESC
   LIMIT ' 
$limit
 array(
 'exclude_boards' => empty($exclude_boards) ? '' $exclude_boards,
 )   
   );
$posts = array();
while (
$row_posts $smcFunc['db_fetch_assoc']($posts_result))
{

      global 
$memberContext;
      
loadMemberData($row_posts['id_member_updated']);
      
loadMemberContext($row_posts['id_member_updated']);

   
$posts[] = array(
   'id' => $row_posts['id_member_updated'],
      
'username' => '<a style="color: ' $row_posts['online_color'] . ';" href="' $scripturl '?action=profile;u=' $row_posts['id_member'] . '">' $row_posts['poster_name'] . '</a>',
      
'subject' => '<a style="font-weight: bold;" title="' $text['board'] . ' ' $row_posts['name'] .'" href="' $scripturl '?topic=' $row_posts['id_topic'] . '.msg' $row_posts['id_last_msg'] . ';topicseen#new">' shorten_subject($row_posts['subject'], 25) . '</a>',
      
'body' => $row_posts['body'],
   'avatar' => $row_posts['avatar'] == '' $memberContext[$row_posts['id_member_updated']]['avatar']['href'] : (stristr($row_posts['avatar'], 'http://') ? $row_posts['avatar'] : $modSettings['avatar_url'] . '/' $row_posts['avatar']),
   'board' => $row_posts['name'], 
   'time' => timeformat($row_posts['poster_time']),
   'new' => !empty($row_posts['is_read'])
   );
}
$smcFunc['db_free_result']($posts_result);

} else {

 if (is_array($exclude_boards) || (int) $exclude_boards === $exclude_boards)
 {
 $exclude_boards is_array($exclude_boards) ? $exclude_boards : array($exclude_boards);
 }
 elseif ($exclude_boards != null)
 {
 $output_method $exclude_boards;
 $exclude_boards = array();
 }

$posts_result $smcFunc['db_query']('''
   SELECT m.poster_name, m.poster_time, m.id_msg, m.id_member, m.subject, m.body, m.id_topic, b.name, b.id_board, u.avatar, g.online_color,' 
. ($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'
) . '
   FROM {db_prefix}messages AS m
   LEFT JOIN {db_prefix}boards AS b ON (m.id_board = b.id_board)
   LEFT JOIN {db_prefix}members AS u ON (m.id_member = u.id_member)
   LEFT JOIN {db_prefix}membergroups AS g ON (g.id_group = CASE WHEN u.id_group = 0 THEN u.id_post_group ELSE u.id_group END)
   ' 
. (!$user_info['is_guest'] ? '
 LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = m.id_topic AND lt.id_member = ' 
$user_info['id'] . ')
 LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = b.id_board AND lmr.id_member = ' 
$user_info['id'] . ')' '') . '   
   WHERE m.approved=1'   
. (empty($exclude_boards) ? '' '
 AND b.id_board NOT IN ({array_int:exclude_boards})'
) . ' AND {query_see_board}
   ORDER BY m.id_msg DESC
   LIMIT ' 
$limit
 array(
 'exclude_boards' => empty($exclude_boards) ? '' $exclude_boards,
 )   
   );
$posts = array();
while (
$row_posts $smcFunc['db_fetch_assoc']($posts_result))
{

      global 
$memberContext;
      
loadMemberData($row_posts['id_member']);
      
loadMemberContext($row_posts['id_member']);

   
$posts[] = array(
   'id' => $row_posts['id_member'],
      
'username' => '<a style="color: ' $row_posts['online_color'] . ';" href="' $scripturl '?action=profile;u=' $row_posts['id_member'] . '">' $row_posts['poster_name'] . '</a>',
      
'subject' => '<a style="font-weight: bold;" title="' $text['board'] . ' ' $row_posts['name'] .'" href="' $scripturl '?topic=' $row_posts['id_topic'] . '.msg' $row_posts['id_msg'] . ';topicseen#new">' shorten_subject($row_posts['subject'], 25) . '</a>',
      
'body' => $row_posts['body'],
    'avatar' => $row_posts['avatar'] == '' $memberContext[$row_posts['id_member']]['avatar']['href'] : (stristr($row_posts['avatar'], 'http://') ? $row_posts['avatar'] : $modSettings['avatar_url'] . '/' $row_posts['avatar']),
   'board' => $row_posts['name'],  
   'time' => timeformat($row_posts['poster_time']),
   'new' => !empty($row_posts['is_read'])
   );
}
$smcFunc['db_free_result']($posts_result);

}

//Finally the Output

//Scrolling xD
if ($scrolling == 1)
echo 

<div style="overflow: hidden;"><marquee height=' 
$height ' behavior="scroll" direction="up" scrollamount="' $speed '" onmouseover="this.stop()" onmouseout="this.start()">';

// Lets fix the BBCode bug and Strip the Text
 
$form_message preg_replace(array('~\n?\[quote.*?\].*\[/quote\]\n?~is''~^\n~''~\[/quote\]~'), ''$post['body']);
$content1 str_replace("[""<"$form_message);
$content2 str_replace("]"">"$content1); 
$content3 strip_tags($content2);
$preview strip_tags(substr (htmlspecialchars_decode($content3),0,$number));

echo '
 
<td><div class="cat_bar">
  <h3 class="catbg">

<table  border="0" cellpadding="0" cellspacing="0" width="100%" colspan="0">
<tr class="">
<td class="son_konular10"><span class="smalltext"><strong>Recent Topics</strong></span></td>
<td class="gonderen10"><span class="smalltext"><strong>Sender</strong></span></td>
<td class="tarih10"><span class="smalltext"><strong>Date</strong></span></td>
</tr></table></h3></div>'
;

echo
'
<span class="upperframe"><span></span></span>
<div class="roundframe">
<table  border="0" cellpadding="0" cellspacing="0" width="100%" colspan="0">'
;

foreach (
$posts as $post) {

echo
'
<tr>
<td class="son_konular10"><img src="'
$settings['images_url'], '/konubasi.gif" style="margin-right:3px;" alt="resim" border="0" />' .str_ireplace('Re: '''$post['subject']);

 if (!$post['new'] && $context['user']['is_logged'])
 echo '&nbsp;<img src="'$settings['images_url'], '/'$context['user']['language'], '/new.gif" alt="new" border="0" />';

echo
'
<hr />
</td>
<td class="gonderen10"><img src="'
$settings['images_url'], '/uyebasi.gif" style="margin-right:3px;" alt="resim" border="0" />' $post['username'] . '<hr /></td> ';

echo
'
 <td class="tarih10"><img src="'
$settings['images_url'], '/tarihbasi.gif" style="margin-right:3px;" alt="resim" border="0" /> ' $post['time'] .'<hr /></td></tr> ';
 }
echo
'

</table>
</div>
<span class="lowerframe"><span></span></span></td>'
;

//Scrolling xD
if ($scrolling == 1)
echo 
'</marquee></div>';
 ?>


2.Block; do not to Active.

Code: [Select]
<?php


/*
Block: 
Author: Blue @ Simple Portal.net
Version: 1.5
*/

/* [SETUP WHAT YOU WANT HERE] */

$topics_posts 2;  // TOPICS - 1 | MESSAGES - 2
$limit 8;  // 
$number 0;  // 
$exclude_boards = array(318427426432425433424,423431434430,429,310);  // IF null guests can see all boards | IF you want to hide some boards use: array( ID1, ID2, ID3) where ID is the board's ID
$htmlspecialcharacters =true//
$default_avatar 'http://img15.hostingpics.net/pics/282198defaultavatar.png';

// Scroll Enable? Height and Speed?
$scrolling 2;       // ENABLE - 1 | DISABLE - 2
$height "0px";
$speed 0;           // SLOW - 1 | MEDIUM - 10 | FAST - 20

// Do you want to translate it to your own language? :P
$text['sportal_false'] = 'Simple Portal not found';
$text['board'] = '';
$text['who'] = '';

/* [STOP!] - THIS IS THE END OF SETUP */

//Only code from now on ;)
global $smcFunc$scripturl$sourcedir$modSettings$user_info$settings$context;

// Lets see if you are using Simple Portal. If not...well...go get them :D
if (!file_exists($sourcedir '/PortalBlocks.php'))
{
 echo $text['sportal_false'];
 return;
}

// Let's grab some database results
if ($topics_posts == 1) {

 if (is_array($exclude_boards) || (int) $exclude_boards === $exclude_boards)
 {
 $exclude_boards is_array($exclude_boards) ? $exclude_boards : array($exclude_boards);
 }
 elseif ($exclude_boards != null)
 {
 $output_method $exclude_boards;
 $exclude_boards = array();
 }

$posts_result $smcFunc['db_query']('''
   SELECT m.poster_name, m.poster_time, m.id_msg, t.id_member_updated, m.subject, m.body, m.id_topic, b.name, t.id_last_msg, u.avatar, g.online_color,' 
. ($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'
) . '
   FROM {db_prefix}topics AS t
   LEFT JOIN {db_prefix}boards AS b ON (t.id_board = b.id_board)
   LEFT JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_last_msg)
   LEFT JOIN {db_prefix}members AS u ON (t.id_member_updated = u.id_member)
   LEFT JOIN {db_prefix}membergroups AS g ON (g.id_group = CASE WHEN u.id_group = 0 THEN u.id_post_group ELSE u.id_group END)
   ' 
. (!$user_info['is_guest'] ? '
 LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = m.id_topic AND lt.id_member = ' 
$user_info['id'] . ')
 LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = b.id_board AND lmr.id_member = ' 
$user_info['id'] . ')' '') . '     
   WHERE m.approved=1'   
. (empty($exclude_boards) ? '' '
 AND b.id_board NOT IN ({array_int:exclude_boards})'
) . ' AND {query_see_board}
   ORDER BY t.id_last_msg DESC
   LIMIT ' 
$limit
 array(
 'exclude_boards' => empty($exclude_boards) ? '' $exclude_boards,
 )   
   );
$posts = array();
while (
$row_posts $smcFunc['db_fetch_assoc']($posts_result))
{

      global 
$memberContext;
      
loadMemberData($row_posts['id_member_updated']);
      
loadMemberContext($row_posts['id_member_updated']);

   
$posts[] = array(
   'id' => $row_posts['id_member_updated'],
      
'username' => '<a style="color: ' $row_posts['online_color'] . ';" href="' $scripturl '?action=profile;u=' $row_posts['id_member_updated'] . '">' $row_posts['poster_name'] . '</a>',
      
'subject' => '<a style="font-weight: bold;" title="' $text['board'] . ' ' $row_posts['name'] .'" href="' $scripturl '?topic=' $row_posts['id_topic'] . '.msg' $row_posts['id_last_msg'] . ';topicseen#new">' shorten_subject($row_posts['subject'], 25) . '</a>',
      
'body' => $row_posts['body'],
   'avatar' => $row_posts['avatar'] == '' $memberContext[$row_posts['id_member_updated']]['avatar']['href'] : (stristr($row_posts['avatar'], 'http://') ? $row_posts['avatar'] : $modSettings['avatar_url'] . '/' $row_posts['avatar']),
   'board' => $row_posts['name'], 
   'time' => timeformat($row_posts['poster_time']),
   'new' => !empty($row_posts['is_read'])
   );
}
$smcFunc['db_free_result']($posts_result);

} else {

 if (is_array($exclude_boards) || (int) $exclude_boards === $exclude_boards)
 {
 $exclude_boards is_array($exclude_boards) ? $exclude_boards : array($exclude_boards);
 }
 elseif ($exclude_boards != null)
 {
 $output_method $exclude_boards;
 $exclude_boards = array();
 }

$posts_result $smcFunc['db_query']('''
   SELECT m.poster_name, m.poster_time, m.id_msg, m.id_member, m.subject, m.body, m.id_topic, b.name, b.id_board, u.avatar, g.online_color,' 
. ($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'
) . '
   FROM {db_prefix}messages AS m
   LEFT JOIN {db_prefix}boards AS b ON (m.id_board = b.id_board)
   LEFT JOIN {db_prefix}members AS u ON (m.id_member = u.id_member)
   LEFT JOIN {db_prefix}membergroups AS g ON (g.id_group = CASE WHEN u.id_group = 0 THEN u.id_post_group ELSE u.id_group END)
   ' 
. (!$user_info['is_guest'] ? '
 LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = m.id_topic AND lt.id_member = ' 
$user_info['id'] . ')
 LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = b.id_board AND lmr.id_member = ' 
$user_info['id'] . ')' '') . '   
   WHERE m.approved=1'   
. (empty($exclude_boards) ? '' '
 AND b.id_board NOT IN ({array_int:exclude_boards})'
) . ' AND {query_see_board}
   ORDER BY m.id_msg DESC
   LIMIT ' 
$limit
 array(
 'exclude_boards' => empty($exclude_boards) ? '' $exclude_boards,
 )   
   );
$posts = array();
while (
$row_posts $smcFunc['db_fetch_assoc']($posts_result))
{

      global 
$memberContext;
      
loadMemberData($row_posts['id_member']);
      
loadMemberContext($row_posts['id_member']);

   
$posts[] = array(
   'id' => $row_posts['id_member'],
      
'username' => '<a style="color: ' $row_posts['online_color'] . ';" href="' $scripturl '?action=profile;u=' $row_posts['id_member'] . '">' $row_posts['poster_name'] . '</a>',
      
'subject' => '<a style="font-weight: bold;" title="' $text['board'] . ' ' $row_posts['name'] .'" href="' $scripturl '?topic=' $row_posts['id_topic'] . '.msg' $row_posts['id_msg'] . ';topicseen#new">' shorten_subject($row_posts['subject'], 25) . '</a>',
      
'body' => $row_posts['body'],
    'avatar' => $row_posts['avatar'] == '' $memberContext[$row_posts['id_member']]['avatar']['href'] : (stristr($row_posts['avatar'], 'http://') ? $row_posts['avatar'] : $modSettings['avatar_url'] . '/' $row_posts['avatar']),
   'board' => $row_posts['name'],  
   'time' => timeformat($row_posts['poster_time']),
   'new' => !empty($row_posts['is_read'])
   );
}
$smcFunc['db_free_result']($posts_result);

}

//Finally the Output

//Scrolling xD
if ($scrolling == 1)
echo 
'                                        <div style="overflow: hidden;"><marquee height=' $height ' behavior="scroll" direction="up" scrollamount="' $speed '" onmouseover="this.stop()" onmouseout="this.start()">';


// Lets fix the BBCode bug and Strip the Text
 
$form_message preg_replace(array('~\n?\[quote.*?\].*\[/quote\]\n?~is''~^\n~''~\[/quote\]~'), ''$post['body']);
$content1 str_replace("[""<"$form_message);
$content2 str_replace("]"">"$content1); 
$content3 strip_tags($content2);
$preview strip_tags(substr (htmlspecialchars_decode($content3),0,$number));

echo '
 
<td><div class="cat_bar">
  <h3 class="catbg">

<table  border="0" cellpadding="0" cellspacing="0" width="100%" colspan="0">
<tr class="">
<td class="son_konular10"><span class="smalltext"><strong>Recent Post</strong></span></td>
<td class="gonderen10"><span class="smalltext"><strong>Sender</strong></span></td>
<td class="tarih10"><span class="smalltext"><strong>Date</strong></span></td>
</tr></table></h3></div>'
;

echo
'
<span class="upperframe"><span></span></span>
<div class="roundframe">
<table  border="0" cellpadding="0" cellspacing="0" width="100%" colspan="0">'
;

foreach (
$posts as $post) {

echo
'
<tr>
<td class="son_konular10"><img src="'
$settings['images_url'], '/konubasi.gif" style="margin-right:3px;" alt="resim" border="0" />' .str_ireplace('Re: '''$post['subject']);

 if (!$post['new'] && $context['user']['is_logged'])
 echo '&nbsp;<img src="'$settings['images_url'], '/'$context['user']['language'], '/new.gif" alt="new" border="0" />';

echo
'
<hr />
</td>
<td class="gonderen10"><img src="'
$settings['images_url'], '/uyebasi.gif" style="margin-right:3px;" alt="resim" border="0" />' $post['username'] . '<hr /></td> ';

echo
'
 <td class="tarih10"><img src="'
$settings['images_url'], '/tarihbasi.gif" style="margin-right:3px;" alt="resim" border="0" /> ' $post['time'] .'<hr /></td></tr> ';
 }
echo
'
</table>
</div>
<span class="lowerframe"><span></span></span></td>'
;

//Scrolling xD
if ($scrolling == 1)
echo 
'</marquee></div>';
 ?>





Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: kimyaci on January 06, 2014, 09:24:46 AM
3.Block:  Is activated.

Code: [Select]
$columns = 14; //
$block_ids = array(253); //

$block_data = array();
foreach ($block_ids as $block)
{
   $block_data[$block] = current(getBlockInfo(false, $block, false, false)); //
   $block_data[$block]['style'] = sportal_parse_style('explode', $block_data[$block]['style'], false); //
}

echo '
 <table border="0" cellpadding="1" cellspacing="0" width="100%" colspan="0">
<tr>';

echo '
<td><table style="width: 100%;">
   <tr>';

$counter = 0;
foreach ($block_data as $data)
{
   if ($counter != 0 && $counter % $columns == 0)
   {
      echo '
   </tr>
   <tr>';
   }

   echo '
      <td style="width: ', ceil((10 / $columns)), '%; vertical-align: top;">
         ', template_block($data), '
      </td>';

   $counter++;
}

echo '
   </tr>
</table></td>';






$columns = 14; //
$block_ids = array(252); //

$block_data = array();
foreach ($block_ids as $block)
{
   $block_data[$block] = current(getBlockInfo(false, $block, false, false)); //
   $block_data[$block]['style'] = sportal_parse_style('explode', $block_data[$block]['style'], false); //
}


echo '
   <td><table style="width: 100%;">
   <tr>';

$counter = 0;
foreach ($block_data as $data)
{
   if ($counter != 0 && $counter % $columns == 0)
   {
      echo '
   </tr>
   <tr>';
   }

   echo '
      <td style="width: ', ceil((10 / $columns)), '%; vertical-align: top;">
         ', template_block($data), '
      </td>';

   $counter++;
}

echo '
   </tr>
</table></td>';

echo '
</tr>
</table>';

Add to your index.css file;
Code: [Select]
.son_konular10{
width: 57%;
text-align: left;
padding: 0px 8px;
cellspacing: 5;
cellpadding: 0;
class: bordercolor;
}
.gonderen10{
width: 17%;
text-align: left;

}
.tarih10{
width: 26%;
text-align: left;
}
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: [SiNaN] on January 06, 2014, 12:57:05 PM
realy nice but stil dont have the smiley's couldn't find any answer

Code: (Find) [Select]
$preview = substr ($content3,0,$number);
Code: (Replace) [Select]
$preview = substr ($content3,0,$number);
parsesmileys($preview);
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: Aquafan on January 14, 2014, 12:00:36 PM
Thank you so mucht that did it   :applause:
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: Petter on February 09, 2014, 05:17:57 AM
Is there a file that needs to be istalled in the package manager to make this work?
Just creating a php block with the code gives me the error:
Quote
Parse error: syntax error, unexpected T_VARIABLE in /home/d/dev/www/Sources/PortalBlocks.php(3561) : eval()'d code on line 18
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: AngelinaBelle on February 09, 2014, 04:09:37 PM
That error message tells you that, on line 18 of what you have pasted into your php block, there is a php error -- unexpected variable.

It does not tell you WHICH block is causing the problem -- there are 3 blocks involved here.

To test this, start by deactivating all 3 blocks.
Then activate block 1 to see if you get the error.
Then turn that one off and test block 2 the same way.
If the error is not in block 1 or block 2, then perhaps it is in block 3 itself (the one which references the other 2 blocks).

In this way, you can begin to narrow down the error to which line is causing the problem.
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: Petter on February 10, 2014, 02:50:51 AM
there are 3 blocks involved here.



I really must have got things wrong here...  :-[
What 3 blocks?
I thought I was supposed to create one php-block and past the code?

Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: AngelinaBelle on February 10, 2014, 02:39:50 PM
There are three different blocks given.  They are numbered 1, 2, and 3.
2 of them are kept inactive.
The third block,, the active one, displays the other two block contents within itself.
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: Tarista on February 25, 2014, 09:28:30 AM
This block seems like it adds 10 queries or so to my page, is that possible to avoid? If I use it twice with limit 5 to each, so I can display both Posts/topics Messages/post it seems to add the double. It seems there is one or two queries per post?  If i inactivate it the queries drop down again.


Edit:
It seems to be this part that adds all the queries.

Code: [Select]
      global $memberContext;
      loadMemberData($row_posts['id_member']);
      loadMemberContext($row_posts['id_member']);
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: AngelinaBelle on February 27, 2014, 07:20:45 PM
Sure.  that code is part of sp_userInfo though, not part of sp_recent
Every block is like a mini-page of your forum -- each one has to fetch info from your database.
You can cut down on the database work by cutting down on the number of blocks on your portal.
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: Tarista on February 28, 2014, 06:16:58 AM
It was part of the custom block-code in the first page, perhaps to grab the avatar or something like that. I excluded it and the avatar as well and that made it load with fewer queries. :)
But while we're on the subject: Does active blocks load in the background even though it doesn't have to load on the page itself? It seems it might at least do that on SP Pages?
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: AngelinaBelle on February 28, 2014, 08:11:59 AM
Every time you load a page, all the work has to be done to load that page.

So, for every block you see on a page, you can look through PortalBlocks.php and through your custom  php code to see exactly which queries are preparing your block.

Only blocks that show on the page have to be run when the page is loaded. Running code for blocks that do not need to be displayed would not make sense.
Of course, whenever SimplePortal is running, it always has to do a query to figure out which blocks are supposed to be displayed on the page.  As the blocks table is typically very much smaller than the messages table, searching for all blocks active on a given page probably means a LOT less work for the database than some searches through the messages table.
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: Tarista on February 28, 2014, 08:20:08 AM
Makes sense :) Thank you for explaining. I guess I have not really learned how to read and completely understand the queries and php just yet.
So then I assume a page with 50 database queries could load faster than one with 27,  depending on the queries?
I've been trying to remove as many queries as I can to load the pages faster, also looking at the page created-time. But I guess I have to look at the code in the queries as well then.
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: AngelinaBelle on March 02, 2014, 06:04:23 PM
You are correct -- it does depend on how complicated the query is, and on how large a table the query has to search, and how much of the table has to search, and on whether it has to search on things that are indexed or not.

There is a certain amount of overhead to any search, so I would be surprised if an "ordinary" page with 50 queries ran faster than one with 27, but you never know....

If you have a TON of messages, then searching the messages table could take a long time (one reason the recent_posts and recent_topics routines limit searches to only the most recent so many messages).  So a full-text search of the entire forum could take a VERY long time.  But a search of the modsettings table could be pretty quick.

How long some queries take can also depend on how your MySQL server is set up -- what it is optimizing and what it is not optimizing, and you probably don't have much control over that.  So many variables.  Indeed, you will have to experiment with turning blocks on and off to see what happens.
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: Rik on May 04, 2014, 08:17:49 AM
Is it possible  to display last post text preview only? for now its shows  recent topics and post in the same time
 and i wondering if its possible to make it display only recent post which was made under topics
 for example
 Title Topic: Recent/post
 Last post: text preview
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: bouch on October 20, 2014, 06:01:56 AM
Hello !

Thanks a lot for this great mod !

I have a question : is it possible to have the same layout as the original post ?

A post formatted like that :
Hello,
- one
- two
- ...

looks like :
Hello,-one-two-...


Thanks !
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: dsystem on November 10, 2014, 09:38:22 PM
[SiNaN] This script is a veritable Swiss Army knife. You can do whatever your imagination allows.

Adding the SQL t.num_replies=0 consultation  did block:

Topics Awaiting Response

Code: [Select]
<?php

/*
Block: Recent posts with post preview
Author: Blue @ Simple Portal.net
Version: 1.6
*/

/* [SETUP WHAT YOU WANT HERE] */

$topics_posts 1; // TOPICS - 1 | MESSAGES - 2
$limit 5; // How many recent posts do you want to output?
$number 70; // How many characters do you want to output?
$exclude_boards null; // IF null guests can see all boards | IF you want to hide some boards use: array( ID1, ID2, ID3) where ID is the board's ID
$htmlspecialcharacters false// Do you need to show html special characters like Greek characters?

// Scroll Enable? Height and Speed?
$scrolling 0;       // ENABLE - 1 | DISABLE - 2
$speed 3;           // SLOW - 1 | MEDIUM - 10 | FAST - 20
$height "150px";
$scrollbar 0;       // ENABLE - 1 | DISABLE - 2

// Do you want to translate it to your own language? :P
$text['sportal_false'] = 'Simple Portal not found';
$text['board'] = 'in';
$text['who'] = 'by';

/* [STOP!] - THIS IS THE END OF SETUP */

//Only code from now on ;)
global $smcFunc$scripturl$sourcedir$modSettings$user_info$settings$context;

// Lets see if you are using Simple Portal. If not...well...go get them :D
if (!file_exists($sourcedir '/PortalBlocks.php'))
{
echo $text['sportal_false'];
return;
}

// Let's grab some database results
if ($topics_posts == 1) {

if (is_array($exclude_boards) || (int) $exclude_boards === $exclude_boards)
{
$exclude_boards is_array($exclude_boards) ? $exclude_boards : array($exclude_boards);
}
elseif ($exclude_boards != null)
{
$output_method $exclude_boards;
$exclude_boards = array();
}

$posts_result $smcFunc['db_query']('''
   SELECT t.num_replies, m.poster_name, m.poster_time, m.id_msg, t.id_member_updated, m.subject, m.body, m.id_topic, b.name, t.id_last_msg, u.avatar, g.online_color,' 
. ($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'
) . '
   FROM {db_prefix}topics AS t
   LEFT JOIN {db_prefix}boards AS b ON (t.id_board = b.id_board)
   LEFT JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_last_msg)
   LEFT JOIN {db_prefix}members AS u ON (t.id_member_updated = u.id_member)
   LEFT JOIN {db_prefix}membergroups AS g ON (g.id_group = CASE WHEN u.id_group = 0 THEN u.id_post_group ELSE u.id_group END)
   ' 
. (!$user_info['is_guest'] ? '
LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = m.id_topic AND lt.id_member = ' 
$user_info['id'] . ')
LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = b.id_board AND lmr.id_member = ' 
$user_info['id'] . ')' '') . '
   WHERE t.num_replies=0 AND m.approved=1'   
. (empty($exclude_boards) ? '' '
AND b.id_board NOT IN ({array_int:exclude_boards})'
) . ' AND {query_see_board}
   ORDER BY t.id_last_msg DESC
   LIMIT ' 
$limit,
array(
'exclude_boards' => empty($exclude_boards) ? '' $exclude_boards,
)
   );
$posts = array();
while (
$row_posts $smcFunc['db_fetch_assoc']($posts_result))
{

      global 
$memberContext;
      
loadMemberData($row_posts['id_member_updated']);
      
loadMemberContext($row_posts['id_member_updated']);

   
$posts[] = array(
  'id' => $row_posts['id_member_updated'],
      
'username' => '<a style="color: ' $row_posts['online_color'] . ';" href="' $scripturl '?action=profile;u=' $row_posts['id_member_updated'] . '">' $row_posts['poster_name'] . '</a>',
      
'subject' => '<a style="font-weight: bold;" title="' $text['board'] . '&nbsp;' $row_posts['name'] .'" href="' $scripturl '?topic=' $row_posts['id_topic'] . '.msg' $row_posts['id_last_msg'] . ';topicseen#new">' $row_posts['subject'] . '</a>',
      
'body' => $row_posts['body'],
  'avatar' => $row_posts['avatar'] == '' $memberContext[$row_posts['id_member_updated']]['avatar']['href'] : (stristr($row_posts['avatar'], 'http://') ? $row_posts['avatar'] : $modSettings['avatar_url'] . '/' $row_posts['avatar']),
  'board' => $row_posts['name'],
  'time' => timeformat($row_posts['poster_time']),
  'new' => !empty($row_posts['is_read'])
   );
}
$smcFunc['db_free_result']($posts_result);

} else {

if (is_array($exclude_boards) || (int) $exclude_boards === $exclude_boards)
{
$exclude_boards is_array($exclude_boards) ? $exclude_boards : array($exclude_boards);
}
elseif ($exclude_boards != null)
{
$output_method $exclude_boards;
$exclude_boards = array();
}

$posts_result $smcFunc['db_query']('''
   SELECT m.poster_name, m.poster_time, m.id_msg, m.id_member, m.subject, m.body, m.id_topic, b.name, b.id_board, u.avatar, g.online_color,' 
. ($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'
) . '
   FROM {db_prefix}messages AS m
   LEFT JOIN {db_prefix}boards AS b ON (m.id_board = b.id_board)
   LEFT JOIN {db_prefix}members AS u ON (m.id_member = u.id_member)
   LEFT JOIN {db_prefix}membergroups AS g ON (g.id_group = CASE WHEN u.id_group = 0 THEN u.id_post_group ELSE u.id_group END)
   ' 
. (!$user_info['is_guest'] ? '
LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = m.id_topic AND lt.id_member = ' 
$user_info['id'] . ')
LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = b.id_board AND lmr.id_member = ' 
$user_info['id'] . ')' '') . '
   WHERE m.approved=1'   
. (empty($exclude_boards) ? '' '
AND b.id_board NOT IN ({array_int:exclude_boards})'
) . ' AND {query_see_board}
   ORDER BY m.id_msg DESC
   LIMIT ' 
$limit,
array(
'exclude_boards' => empty($exclude_boards) ? '' $exclude_boards,
)
   );
$posts = array();
while (
$row_posts $smcFunc['db_fetch_assoc']($posts_result))
{

      global 
$memberContext;
      
loadMemberData($row_posts['id_member']);
      
loadMemberContext($row_posts['id_member']);

   
$posts[] = array(
  'id' => $row_posts['id_member'],
      
'username' => '<a style="color: ' $row_posts['online_color'] . ';" href="' $scripturl '?action=profile;u=' $row_posts['id_member'] . '">' $row_posts['poster_name'] . '</a>',
      
'subject' => '<a style="font-weight: bold;" title="' $text['board'] . '&nbsp;' $row_posts['name'] .'" href="' $scripturl '?topic=' $row_posts['id_topic'] . '.msg' $row_posts['id_msg'] . ';topicseen#new">' $row_posts['subject'] . '</a>',
      
'body' => $row_posts['body'],
  'avatar' => $row_posts['avatar'] == '' $memberContext[$row_posts['id_member']]['avatar']['href'] : (stristr($row_posts['avatar'], 'http://') ? $row_posts['avatar'] : $modSettings['avatar_url'] . '/' $row_posts['avatar']),
  'board' => $row_posts['name'],
  'time' => timeformat($row_posts['poster_time']),
  'new' => !empty($row_posts['is_read'])
   );
}
$smcFunc['db_free_result']($posts_result);

}

//Finally the Output

//Scrolling xD
if ($scrolling == 1)
echo 
'<div style="overflow: hidden;"><marquee height=' $height ' behavior="scroll" direction="up" scrollamount="' $speed '" onmouseover="this.stop()" onmouseout="this.start()">';

if (
$scrollbar == 1)
echo 
'<div style="height:' $height '; overflow-y: scroll; overflow-x: hidden;">';

foreach (
$posts as $post) {

// Lets fix the BBCode bug and Strip the Text
$content1 str_replace("[""<"$post['body']);
$content2 str_replace("]"">"$content1);
$content3 strip_tags($content2);
$preview substr ($content3,0,$number);

echo
'<table>
<tr>
<td style="width: 40px;">
<img src="' 
$post['avatar'] .'" alt="" width="40px" height="40px" />
</td>
<td>
$post['subject'];

if (!$post['new'] && $context['user']['is_logged'])
echo '&nbsp;<img src="'$settings['images_url'], '/'$context['user']['language'], '/new.gif" alt="new" border="0" />';

echo '<br />
<small>' 
$text['who'] . '&nbsp;' $post['username'] . '&nbsp;|&nbsp;' $post['time'] .'</small>
</td>
</tr>
</table>'
;

if ($htmlspecialcharacters) {
echo htmlspecialchars($previewENT_NOQUOTES"UTF-8") . '...';
} else {
echo $preview '...';
}

echo 
'<hr />';
}

//Scrolling xD
if ($scrollbar == 1)
echo 
'</div>';

if (
$scrolling == 1)
echo 
'</marquee></div>';
?>
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: Burke Knight on December 09, 2014, 05:24:52 PM
Is there any way to change it so instead of displaying the username for the poster, it shows the display name?
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: mrnuke7175 on January 31, 2015, 09:34:03 PM
Hello !

Thanks a lot for this great mod !

I have a question : is it possible to have the same layout as the original post ?

A post formatted like that :
Hello,
- one
- two
- ...

looks like :
Hello,-one-two-...


Thanks !

I'm wondering about the same thing. :-)
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: dtek on February 12, 2015, 03:53:57 PM
The version of mod_security my host uses does not allow for user toggling and I get this error.

Not Implemented

GET to /index.php not supported.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

I have edited the .htacces file but obviously that didn't work Any ideas?
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: ♦ Ninja ZX-10RR ♦ on February 12, 2015, 04:08:19 PM
That has nothing to deal with this block. It's an SMF issue and the solution is... Get a decent host. Try to contact them and ask them to remove that restriction, if you can.
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: dtek on February 12, 2015, 04:22:14 PM
ohhhhhhhhh

I thought it did have something to deal with this block. Excuse me for not knowing it was SMF and not the Simpleportal block itself and asking for assistance. I really thought the author of the code would be a good person to ask. I guess after five days I should have known that. I did speak to the host and they can not turn it off. Maybe I shall just finish the site and move on to a new host and add the block then.

I will head over to SMF now. Thank you so very much pal.




Edit:

Actually you are dead right, I got the same reply from SMF regarding the host. Cheerz

Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: ♦ Ninja ZX-10RR ♦ on February 12, 2015, 05:26:56 PM
I know, I used to be there until I quitted it for some people being... Let's say "questionable", especially the high ranked ones.
Get a better host @_@ unfortunately your smf installation won't work properly if your host doesn't disable mod_security, plus they are not experienced at all if they think it's that necessary :/
You're welcome, unfortunately there is not much you can do except switching host and tell your actual one to... *insert vulgar sentence here* :P
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: 420connect on February 17, 2015, 07:57:17 PM
Hey SP!
I'm loving this box and the idea of customising it a little bit further if possible...

I was wondering if it's able to get my smileys to 'parse' in the custom block?

also, when I try to hide boards from being included I get a very strange css error? :S
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: 420connect on March 07, 2015, 05:39:48 AM
Still looking to parse smileys in this block but have managed to solve my excluded boards error..

Using: $exclude_boards = array(87, 93, 17, 71);

where as before I was trying to use: $exclude_boards = array( ID87, ID93, ID17, ID71);
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: ♦ Ninja ZX-10RR ♦ on March 07, 2015, 05:46:07 AM
I might be wrong but if you added a parseSmileys maybe...? http://support.simplemachines.org/function_db/index.php?action=view_function;id=220
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: 420connect on March 16, 2015, 09:18:04 AM
Thanks for the link Ninja although my attempts have failed to add it in properly, I'll get it solved one day! .   ;P



A new idea for this I am hoping wouldn't be too difficult..

I really like what this block offers, but would also like to use the "Advanced Unread Posts" - However I'd ideally like to keep the styling of the 2 the same.

I am wondering could anyone help with tweaking the below code to show a users unread posts, but using the same display as is below.

Code: [Select]
<?php

/*
Block: Recent posts with post preview
Author: Blue @ Simple Portal.net
Version: 1.6
*/

/* [SETUP WHAT YOU WANT HERE] */

$topics_posts 2; // TOPICS - 1 | MESSAGES - 2
$limit 100; // How many recent posts do you want to output?
$number 240; // How many characters do you want to output?
$exclude_boards = array(87931771); // IF null guests can see all boards | IF you want to hide some boards use: array( ID1, ID2, ID3) where ID is the board's ID
$htmlspecialcharacters false// Do you need to show html special characters like Greek characters?

// Scroll Enable? Height and Speed?
$scrolling 2;       // ENABLE - 1 | DISABLE - 2
$speed 4;           // SLOW - 1 | MEDIUM - 10 | FAST - 20
$height "700px";
$scrollbar 1;       // ENABLE - 1 | DISABLE - 2

// Do you want to translate it to your own language? :P
$text['sportal_false'] = 'Simple Portal not found';
$text['board'] = 'in';
$text['who'] = 'by';

/* [STOP!] - THIS IS THE END OF SETUP */

//Only code from now on ;)
global $smcFunc$scripturl$sourcedir$modSettings$user_info$settings$context;

// Lets see if you are using Simple Portal. If not...well...go get them :D
if (!file_exists($sourcedir '/PortalBlocks.php'))
{
echo $text['sportal_false'];
return;
}

// Let's grab some database results
if ($topics_posts == 1) {

if (is_array($exclude_boards) || (int) $exclude_boards === $exclude_boards)
{
$exclude_boards is_array($exclude_boards) ? $exclude_boards : array($exclude_boards);
}
elseif ($exclude_boards != null)
{
$output_method $exclude_boards;
$exclude_boards = array();
}

$posts_result $smcFunc['db_query']('''
   SELECT IFNULL(u.real_name, m.poster_name) AS poster_name, m.poster_time, m.id_msg, t.id_member_updated, m.subject, m.body, m.id_topic, b.name, t.id_last_msg, u.avatar, g.online_color,' 
. ($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'
) . '
   FROM {db_prefix}topics AS t
   LEFT JOIN {db_prefix}boards AS b ON (t.id_board = b.id_board)
   LEFT JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_last_msg)
   LEFT JOIN {db_prefix}members AS u ON (t.id_member_updated = u.id_member)
   LEFT JOIN {db_prefix}membergroups AS g ON (g.id_group = CASE WHEN u.id_group = 0 THEN u.id_post_group ELSE u.id_group END)
   ' 
. (!$user_info['is_guest'] ? '
LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = m.id_topic AND lt.id_member = ' 
$user_info['id'] . ')
LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = b.id_board AND lmr.id_member = ' 
$user_info['id'] . ')' '') . '     
   WHERE m.approved=1'   
. (empty($exclude_boards) ? '' '
AND b.id_board NOT IN ({array_int:exclude_boards})'
) . ' AND {query_see_board}
   ORDER BY t.id_last_msg DESC
   LIMIT ' 
$limit
array(
'exclude_boards' => empty($exclude_boards) ? '' $exclude_boards,
)   
   );
$posts = array();
while (
$row_posts $smcFunc['db_fetch_assoc']($posts_result))
{

      global 
$memberContext;
      
loadMemberData($row_posts['id_member_updated']);
      
loadMemberContext($row_posts['id_member_updated']);

   
$posts[] = array(
  'id' => $row_posts['id_member_updated'],
      
'username' => '<a style="color: ' $row_posts['online_color'] . ';" href="' $scripturl '?action=profile;u=' $row_posts['id_member_updated'] . '">' $row_posts['poster_name'] . '</a>',
      
'subject' => '<a style="font-weight: bold;" title="' $text['board'] . '&nbsp;' $row_posts['name'] .'" href="' $scripturl '?topic=' $row_posts['id_topic'] . '.msg' $row_posts['id_last_msg'] . ';topicseen#new">' $row_posts['subject'] . '</a>',
      
'body' => parse_bbc($row_posts['body']),
  'avatar' => $row_posts['avatar'] == '' $memberContext[$row_posts['id_member_updated']]['avatar']['href'] : (stristr($row_posts['avatar'], 'http://') ? $row_posts['avatar'] : $modSettings['avatar_url'] . '/' $row_posts['avatar']),
  'board' => $row_posts['name'], 
  'time' => timeformat($row_posts['poster_time']),
  'new' => !empty($row_posts['is_read'])
   );
}
$smcFunc['db_free_result']($posts_result);

} else {

if (is_array($exclude_boards) || (int) $exclude_boards === $exclude_boards)
{
$exclude_boards is_array($exclude_boards) ? $exclude_boards : array($exclude_boards);
}
elseif ($exclude_boards != null)
{
$output_method $exclude_boards;
$exclude_boards = array();
}

$posts_result $smcFunc['db_query']('''
   SELECT IFNULL(u.real_name, m.poster_name) AS poster_name, m.poster_time, m.id_msg, m.id_member, m.subject, m.body, m.id_topic, b.name, b.id_board, u.avatar, g.online_color,' 
. ($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'
) . '
   FROM {db_prefix}messages AS m
   LEFT JOIN {db_prefix}boards AS b ON (m.id_board = b.id_board)
   LEFT JOIN {db_prefix}members AS u ON (m.id_member = u.id_member)
   LEFT JOIN {db_prefix}membergroups AS g ON (g.id_group = CASE WHEN u.id_group = 0 THEN u.id_post_group ELSE u.id_group END)
   ' 
. (!$user_info['is_guest'] ? '
LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = m.id_topic AND lt.id_member = ' 
$user_info['id'] . ')
LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = b.id_board AND lmr.id_member = ' 
$user_info['id'] . ')' '') . '   
   WHERE m.approved=1'   
. (empty($exclude_boards) ? '' '
AND b.id_board NOT IN ({array_int:exclude_boards})'
) . ' AND {query_see_board}
   ORDER BY m.id_msg DESC
   LIMIT ' 
$limit
array(
'exclude_boards' => empty($exclude_boards) ? '' $exclude_boards,
)   
   );
$posts = array();
while (
$row_posts $smcFunc['db_fetch_assoc']($posts_result))
{

      global 
$memberContext;
      
loadMemberData($row_posts['id_member']);
      
loadMemberContext($row_posts['id_member']);

   
$posts[] = array(
  'id' => $row_posts['id_member'],
      
'username' => '<a style="color: ' $row_posts['online_color'] . ';" href="' $scripturl '?action=profile;u=' $row_posts['id_member'] . '">' $row_posts['poster_name'] . '</a>',
      
'subject' => '<a style="font-weight: bold;" title="' $text['board'] . '&nbsp;' $row_posts['name'] .'" href="' $scripturl '?topic=' $row_posts['id_topic'] . '.msg' $row_posts['id_msg'] . ';topicseen#new">' $row_posts['subject'] . '</a>',
      
'body' => parse_bbc($row_posts['body']),
  'avatar' => $row_posts['avatar'] == '' $memberContext[$row_posts['id_member']]['avatar']['href'] : (stristr($row_posts['avatar'], 'http://') ? $row_posts['avatar'] : $modSettings['avatar_url'] . '/' $row_posts['avatar']),
  'board' => $row_posts['name'],  
  'time' => timeformat($row_posts['poster_time']),
  'new' => !empty($row_posts['is_read'])
   );
}
$smcFunc['db_free_result']($posts_result);

}

//Finally the Output

//Scrolling xD
if ($scrolling == 1)
echo 
'<div style="overflow: hidden;"><marquee height=' $height ' behavior="scroll" direction="up" scrollamount="' $speed '" onmouseover="this.stop()" onmouseout="this.start()">';

if (
$scrollbar == 1)
echo 
'<div style="height:' $height '; overflow-y: scroll; overflow-x: hidden;">';

foreach (
$posts as $post) {

// Lets fix the BBCode bug and Strip the Text
$content1 str_replace("[""<"$post['body']);
$content2 str_replace("]"">"$content1); 
$content3 strip_tags($content2);
$preview substr ($content3,0,$number);

echo
'<table>
<tr>
<td style="width: 40px;">
<img src="' 
$post['avatar'] .'" alt="" width="40px" height="40px" />
</td>
<td>
$post['subject'];

if (!$post['new'] && $context['user']['is_logged'])
echo '&nbsp;<img src="'$settings['images_url'], '/'$context['user']['language'], '/new.gif" alt="new" border="0" />';

echo '<br />
<small>' 
$text['who'] . '&nbsp;' $post['username'] . '&nbsp;|&nbsp;' $post['time'] .'</small>
</td>
</tr>
</table>'
;

if ($htmlspecialcharacters) {
echo htmlspecialchars($previewENT_NOQUOTES"UTF-8") . '...';
} else {
echo $preview '...';
}

echo 
'<hr />';
}
        
//Scrolling xD
if ($scrollbar == 1)
echo 
'</div>'

if (
$scrolling == 1)
echo 
'</marquee></div>';
?>
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: 420connect on April 04, 2015, 06:08:28 AM
realy nice but stil dont have the smiley's couldn't find any answer

Code: (Find) [Select]
$preview = substr ($content3,0,$number);
Code: (Replace) [Select]
$preview = substr ($content3,0,$number);
parsesmileys($preview);





edit - another little thing I'd like to add if it's not a huge job..

Currently, I use the forum's word censor to clean up a few strange characters that appear when grabbing an RSS feed. (e.g. "“" is censored to be replaced with "")

- Could I tell the block to use the same censor rules?


I should have better searched this thread before asking for the smileys fix - however I've just tested this and with the additional line, still my smileys don't show? :(
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: xeon365 on October 01, 2015, 05:13:52 PM
Someone got an edit to make the block, show the users actual 'Name' ..and not use the 'Username'

Even in SMF own profile it reads

"Name
This is the displayed name that people will see"

yet this block uses the username field..
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: ccbtimewiz on October 01, 2015, 05:58:12 PM
Someone got an edit to make the block, show the users actual 'Name' ..and not use the 'Username'

Even in SMF own profile it reads

"Name
This is the displayed name that people will see"

yet this block uses the username field..

You'll need to modify the queries.

Find:
Code: [Select]
SELECT m.poster_name, m.poster_time,
Replace with:
Code: [Select]
SELECT m.poster_time,
You will need to do this twice.

Find:
Code: [Select]
IFNULL(lt.id_msg, IFNULL(lmr.id_msg, 0)) >= m.id_msg_modified AS is_read,
Replace with:
Code: [Select]
IFNULL(u.real_name, m.poster_name) AS poster_name,
IFNULL(lt.id_msg, IFNULL(lmr.id_msg, 0)) >= m.id_msg_modified AS is_read,

You will need to do this twice.
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: xeon365 on October 01, 2015, 07:46:17 PM
works great thanks
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: ♦ Ninja ZX-10RR ♦ on October 01, 2015, 08:07:59 PM
Thank you Sayaka Maizono Classic Sonic Sayaka Maizono (lol at that name change) for the edit and thank you xeon for confirming it works.
Since showing the username instead of the display name is generally a bad practice, and considering that Blue is not very active I'll go ahead and edit the OP with the suggested changes.

Regards to both!
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: ccbtimewiz on October 01, 2015, 10:26:50 PM
Thank you Sayaka Maizono for the edit and thank you xeon for confirming it works.
Since showing the username instead of the display name is generally a bad practice, and considering that Blue is not very active I'll go ahead and edit the OP with the suggested changes.

Regards to both!

It's no problem, thanks for adding it.
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: dhayzon on March 30, 2016, 04:32:55 PM
how to show menber group name?   group_name
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: GeorG on August 11, 2016, 08:51:32 AM
1. Icon "NEW" disappears when the message has been read
2. Guests are shown author nick

RU:
1. Иконка "NEW" исчезает когда сообщение прочитано
2. Гостям показывается ник автора

Code: [Select]
<?php

/*
Block: Recent posts with post preview
Author: Blue @ Simple Portal.net
Version: 1.8
*/

/* [SETUP WHAT YOU WANT HERE] */

$topics_posts 1; // TOPICS - 1 | MESSAGES - 2
$limit 5; // How many recent posts do you want to output?
$number 70; // How many characters do you want to output?
$exclude_boards null; // IF null guests can see all boards | IF you want to hide some boards use: array( ID1, ID2, ID3) where ID is the board's ID
$htmlspecialcharacters false// Do you need to show html special characters like Greek characters?

// Scroll Enable? Height and Speed?
$scrolling 0;       // ENABLE - 1 | DISABLE - 2
$speed 3;           // SLOW - 1 | MEDIUM - 10 | FAST - 20
$height "150px";
$scrollbar 0;       // ENABLE - 1 | DISABLE - 2

// Do you want to translate it to your own language? :P
$text['sportal_false'] = 'Simple Portal not found';

/* [STOP!] - THIS IS THE END OF SETUP */

//Only code from now on ;)
global $smcFunc$scripturl$sourcedir$modSettings$user_info$settings$context$txt;

// Lets see if you are using Simple Portal. If not...well...go get them :D
if (!file_exists($sourcedir '/PortalBlocks.php'))
{
echo $text['sportal_false'];
return;
}

// Let's grab some database results
if ($topics_posts == 1) {

if (is_array($exclude_boards) || (int) $exclude_boards === $exclude_boards)
{
$exclude_boards is_array($exclude_boards) ? $exclude_boards : array($exclude_boards);
}
elseif ($exclude_boards != null)
{
$output_method $exclude_boards;
$exclude_boards = array();
}

$posts_result $smcFunc['db_query']('''
   SELECT m.poster_time, m.id_msg, t.id_member_updated, m.subject, m.body, m.id_topic, b.name, t.id_last_msg, IFNULL(u.real_name, m.poster_name) AS poster_name, u.avatar, g.online_color,' 
. ($user_info['is_guest'] ? '1 AS is_read, 0 AS new_from' '
(IFNULL(lb.id_msg, 0) >= b.id_msg_updated) AS is_read,
IFNULL(lb.id_msg, -1) + 1 AS new_from'
) . '
   FROM {db_prefix}topics AS t
   LEFT JOIN {db_prefix}boards AS b ON (t.id_board = b.id_board)
   LEFT JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_last_msg)
   LEFT JOIN {db_prefix}members AS u ON (t.id_member_updated = u.id_member)' 
. ($user_info['is_guest'] ? '' '
   LEFT JOIN {db_prefix}log_boards AS lb ON (lb.id_board = b.id_board AND lb.id_member = {int:current_member})'
) . '
   LEFT JOIN {db_prefix}membergroups AS g ON (g.id_group = CASE WHEN u.id_group = 0 THEN u.id_post_group ELSE u.id_group END)
   ' 
. (!$user_info['is_guest'] ? '
LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = m.id_topic AND lt.id_member = ' 
$user_info['id'] . ')
LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = b.id_board AND lmr.id_member = ' 
$user_info['id'] . ')' '') . '     
   WHERE m.approved=1'   
. (empty($exclude_boards) ? '' '
AND b.id_board NOT IN ({array_int:exclude_boards})'
) . ' AND {query_see_board}
   ORDER BY t.id_last_msg DESC
   LIMIT ' 
$limit
array(
'exclude_boards' => empty($exclude_boards) ? '' $exclude_boards,
'current_member' => $user_info['id'],
)   
   );
$posts = array();
while (
$row_posts $smcFunc['db_fetch_assoc']($posts_result))
{

      global 
$memberContext;
      
loadMemberData($row_posts['id_member_updated']);
      
loadMemberContext($row_posts['id_member_updated']);

   
$posts[] = array(
  'id' => $row_posts['id_member_updated'],
      
'username' => '<a style="color: ' $row_posts['online_color'] . ';" href="' $scripturl '?action=profile;u=' $row_posts['id_member_updated'] . '">' $row_posts['poster_name'] . '</a>',
      
'subject' => '<a style="font-weight: bold;" title="' $txt['board'] . ':&nbsp;' $row_posts['name'] .'" href="' $scripturl '?topic=' $row_posts['id_topic'] . '.msg' $row_posts['id_last_msg'] . ';topicseen#new">' $row_posts['subject'] . '</a>',
      
'body' => $row_posts['body'],
  'avatar' => $row_posts['avatar'] == '' $memberContext[$row_posts['id_member_updated']]['avatar']['href'] : (stristr($row_posts['avatar'], 'http://') ? $row_posts['avatar'] : $modSettings['avatar_url'] . '/' $row_posts['avatar']),
  'board' => $row_posts['name'], 
  'time' => timeformat($row_posts['poster_time']),
  'new' => !empty($row_posts['is_read']),
      
'subject_new' => $scripturl '?topic=' $row_posts['id_topic'] . '.msg' $row_posts['id_msg'] . ';topicseen#new'
   
);
}
$smcFunc['db_free_result']($posts_result);

} else {

if (is_array($exclude_boards) || (int) $exclude_boards === $exclude_boards)
{
$exclude_boards is_array($exclude_boards) ? $exclude_boards : array($exclude_boards);
}
elseif ($exclude_boards != null)
{
$output_method $exclude_boards;
$exclude_boards = array();
}

$posts_result $smcFunc['db_query']('''
   SELECT m.poster_time, m.id_msg, m.id_member, m.subject, m.body, m.id_topic, b.name, b.id_board, IFNULL(u.real_name, m.poster_name) AS poster_name, u.avatar, g.online_color,' 
. ($user_info['is_guest'] ? '1 AS is_read, 0 AS new_from' '
(IFNULL(lb.id_msg, 0) >= b.id_msg_updated) AS is_read,
IFNULL(lb.id_msg, -1) + 1 AS new_from'
) . '
   FROM {db_prefix}messages AS m
   LEFT JOIN {db_prefix}boards AS b ON (m.id_board = b.id_board)
   LEFT JOIN {db_prefix}members AS u ON (m.id_member = u.id_member)' 
. ($user_info['is_guest'] ? '' '
   LEFT JOIN {db_prefix}log_boards AS lb ON (lb.id_board = b.id_board AND lb.id_member = {int:current_member})'
) . '
   LEFT JOIN {db_prefix}membergroups AS g ON (g.id_group = CASE WHEN u.id_group = 0 THEN u.id_post_group ELSE u.id_group END)
   ' 
. (!$user_info['is_guest'] ? '
LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = m.id_topic AND lt.id_member = ' 
$user_info['id'] . ')
LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = b.id_board AND lmr.id_member = ' 
$user_info['id'] . ')' '') . '   
   WHERE m.approved=1'   
. (empty($exclude_boards) ? '' '
AND b.id_board NOT IN ({array_int:exclude_boards})'
) . ' AND {query_see_board}
   ORDER BY m.id_msg DESC
   LIMIT ' 
$limit
array(
'exclude_boards' => empty($exclude_boards) ? '' $exclude_boards,
'current_member' => $user_info['id'],
)   
   );
$posts = array();
while (
$row_posts $smcFunc['db_fetch_assoc']($posts_result))
{

      global 
$memberContext;
      
loadMemberData($row_posts['id_member']);
      
loadMemberContext($row_posts['id_member']);

   
$posts[] = array(
  'id' => $row_posts['id_member'],
      
'username' => '<a style="color: ' $row_posts['online_color'] . ';" href="' $scripturl '?action=profile;u=' $row_posts['id_member'] . '">' $row_posts['poster_name'] . '</a>',
      
'subject' => '<a style="font-weight: bold;" title="' $txt['board'] . ':&nbsp;' $row_posts['name'] .'" href="' $scripturl '?topic=' $row_posts['id_topic'] . '.msg' $row_posts['id_msg'] . ';topicseen#new">' $row_posts['subject'] . '</a>',
      
'body' => $row_posts['body'],
  'avatar' => $row_posts['avatar'] == '' $memberContext[$row_posts['id_member']]['avatar']['href'] : (stristr($row_posts['avatar'], 'http://') ? $row_posts['avatar'] : $modSettings['avatar_url'] . '/' $row_posts['avatar']),
  'board' => $row_posts['name'],  
  'time' => timeformat($row_posts['poster_time']),
  'new' => !empty($row_posts['is_read']),
      
'subject_new' => $scripturl '?topic=' $row_posts['id_topic'] . '.msg' $row_posts['id_msg'] . ';topicseen#new'
   
);
}
$smcFunc['db_free_result']($posts_result);

}

//Finally the Output

//Scrolling xD
if ($scrolling == 1)
echo 
'<div style="overflow: hidden;"><marquee height=' $height ' behavior="scroll" direction="up" scrollamount="' $speed '" onmouseover="this.stop()" onmouseout="this.start()">';

if (
$scrollbar == 1)
echo 
'<div style="height:' $height '; overflow-y: scroll; overflow-x: hidden;">';

foreach (
$posts as $post) {

// Lets fix the BBCode bug and Strip the Text
$content1 str_replace("[""<"$post['body']);
$content2 str_replace("]"">"$content1); 
$content3 strip_tags($content2);
$preview substr ($content3,0,$number);

echo
'<table>
<tr>
<td style="width: 40px;">
<img src="' 
$post['avatar'] .'" alt="" width="40px" height="40px" />
</td>
<td>
$post['subject'];

if (!$post['new'] && $context['user']['is_logged'])
echo '&nbsp;<a href=' $post['subject_new'] . '><img src="'$settings['images_url'], '/'$context['user']['language'], '/new.gif" alt="new" border="0" /></a>';

echo '<br />
<small>' 
$txt['by'] . '&nbsp;' $post['username'] . '&nbsp;|&nbsp;' $post['time'] .'</small>
</td>
</tr>
</table>'
;

if ($htmlspecialcharacters) {
echo htmlspecialchars($previewENT_NOQUOTES"UTF-8") . '...';
} else {
echo $preview '...';
}

echo 
'<hr />';
}
        
//Scrolling xD
if ($scrollbar == 1)
echo 
'</div>'

if (
$scrolling == 1)
echo 
'</marquee></div>';
?>
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: Blue on August 13, 2016, 05:39:41 PM
Thanks for you changes GeorG :)
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: ♦ Ninja ZX-10RR ♦ on August 14, 2016, 02:19:12 AM
Do you want to make it the official version Blue? I updated it once last time since it was showing usernames (not an awesome practice). :)
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: Ian M on November 09, 2016, 07:54:01 PM
Hoping someone can help me with this please.

When the block is being viewed by a guest, the name of the poster is missing. The poster name shows for all other member groups.

Have attached an example where the top image is the guest view and the lower image is any other member group view.


Quick Edit:
I forgot to mention that for Guests only, the following error log is created:

Code: [Select]
Undefined index: poster_name
File: /home/xxxxxxx/public_html/forum/Sources/PortalBlocks.php(3674) : eval()'d code
Line: 83

Hope this helps !!
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: andy on November 10, 2016, 06:03:45 AM
I am using this block and its working fine so your problem is related to something else.

Did you make any changes to the block code?

What mods are you using? Always best to list them when you ask a question.

Any permission settings you might have changed - for member groups.

Andy
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: Ian M on November 10, 2016, 07:04:12 AM
I am using this block and its working fine so your problem is related to something else.

I think the problem may be I'm using the original code from a quite a while back and hadn't realised there'd been so many tweaks to it !!

It's been installed for almost a year, and it's only this week when guest access has been allowed onto the forum that the problem has come to light.The only changes that were made to the code were to the array board id's which work fine.

However, having installed the latest code in a hidden block it's working no problem.

I guess I shouldn't be up until 2am looking for something that's blatantly obvious in the morning !!
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: owenenene on January 14, 2017, 05:56:37 AM
1. Icon "NEW" disappears when the message has been read
2. Guests are shown author nick

RU:
1. Иконка "NEW" исчезает когда сообщение прочитано
2. Гостям показывается ник автора

Code: [Select]
<?php

/*
Block: Recent posts with post preview
Author: Blue @ Simple Portal.net
Version: 1.8
*/

/* [SETUP WHAT YOU WANT HERE] */

$topics_posts 1; // TOPICS - 1 | MESSAGES - 2
$limit 5; // How many recent posts do you want to output?
$number 70; // How many characters do you want to output?
$exclude_boards null; // IF null guests can see all boards | IF you want to hide some boards use: array( ID1, ID2, ID3) where ID is the board's ID
$htmlspecialcharacters false// Do you need to show html special characters like Greek characters?

// Scroll Enable? Height and Speed?
$scrolling 0;       // ENABLE - 1 | DISABLE - 2
$speed 3;           // SLOW - 1 | MEDIUM - 10 | FAST - 20
$height "150px";
$scrollbar 0;       // ENABLE - 1 | DISABLE - 2

// Do you want to translate it to your own language? :P
$text['sportal_false'] = 'Simple Portal not found';

/* [STOP!] - THIS IS THE END OF SETUP */

//Only code from now on ;)
global $smcFunc$scripturl$sourcedir$modSettings$user_info$settings$context$txt;

// Lets see if you are using Simple Portal. If not...well...go get them :D
if (!file_exists($sourcedir '/PortalBlocks.php'))
{
echo $text['sportal_false'];
return;
}

// Let's grab some database results
if ($topics_posts == 1) {

if (is_array($exclude_boards) || (int) $exclude_boards === $exclude_boards)
{
$exclude_boards is_array($exclude_boards) ? $exclude_boards : array($exclude_boards);
}
elseif ($exclude_boards != null)
{
$output_method $exclude_boards;
$exclude_boards = array();
}

$posts_result $smcFunc['db_query']('''
   SELECT m.poster_time, m.id_msg, t.id_member_updated, m.subject, m.body, m.id_topic, b.name, t.id_last_msg, IFNULL(u.real_name, m.poster_name) AS poster_name, u.avatar, g.online_color,' 
. ($user_info['is_guest'] ? '1 AS is_read, 0 AS new_from' '
(IFNULL(lb.id_msg, 0) >= b.id_msg_updated) AS is_read,
IFNULL(lb.id_msg, -1) + 1 AS new_from'
) . '
   FROM {db_prefix}topics AS t
   LEFT JOIN {db_prefix}boards AS b ON (t.id_board = b.id_board)
   LEFT JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_last_msg)
   LEFT JOIN {db_prefix}members AS u ON (t.id_member_updated = u.id_member)' 
. ($user_info['is_guest'] ? '' '
   LEFT JOIN {db_prefix}log_boards AS lb ON (lb.id_board = b.id_board AND lb.id_member = {int:current_member})'
) . '
   LEFT JOIN {db_prefix}membergroups AS g ON (g.id_group = CASE WHEN u.id_group = 0 THEN u.id_post_group ELSE u.id_group END)
   ' 
. (!$user_info['is_guest'] ? '
LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = m.id_topic AND lt.id_member = ' 
$user_info['id'] . ')
LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = b.id_board AND lmr.id_member = ' 
$user_info['id'] . ')' '') . '     
   WHERE m.approved=1'   
. (empty($exclude_boards) ? '' '
AND b.id_board NOT IN ({array_int:exclude_boards})'
) . ' AND {query_see_board}
   ORDER BY t.id_last_msg DESC
   LIMIT ' 
$limit
array(
'exclude_boards' => empty($exclude_boards) ? '' $exclude_boards,
'current_member' => $user_info['id'],
)   
   );
$posts = array();
while (
$row_posts $smcFunc['db_fetch_assoc']($posts_result))
{

      global 
$memberContext;
      
loadMemberData($row_posts['id_member_updated']);
      
loadMemberContext($row_posts['id_member_updated']);

   
$posts[] = array(
  'id' => $row_posts['id_member_updated'],
      
'username' => '<a style="color: ' $row_posts['online_color'] . ';" href="' $scripturl '?action=profile;u=' $row_posts['id_member_updated'] . '">' $row_posts['poster_name'] . '</a>',
      
'subject' => '<a style="font-weight: bold;" title="' $txt['board'] . ':&nbsp;' $row_posts['name'] .'" href="' $scripturl '?topic=' $row_posts['id_topic'] . '.msg' $row_posts['id_last_msg'] . ';topicseen#new">' $row_posts['subject'] . '</a>',
      
'body' => $row_posts['body'],
  'avatar' => $row_posts['avatar'] == '' $memberContext[$row_posts['id_member_updated']]['avatar']['href'] : (stristr($row_posts['avatar'], 'http://') ? $row_posts['avatar'] : $modSettings['avatar_url'] . '/' $row_posts['avatar']),
  'board' => $row_posts['name'], 
  'time' => timeformat($row_posts['poster_time']),
  'new' => !empty($row_posts['is_read']),
      
'subject_new' => $scripturl '?topic=' $row_posts['id_topic'] . '.msg' $row_posts['id_msg'] . ';topicseen#new'
   
);
}
$smcFunc['db_free_result']($posts_result);

} else {

if (is_array($exclude_boards) || (int) $exclude_boards === $exclude_boards)
{
$exclude_boards is_array($exclude_boards) ? $exclude_boards : array($exclude_boards);
}
elseif ($exclude_boards != null)
{
$output_method $exclude_boards;
$exclude_boards = array();
}

$posts_result $smcFunc['db_query']('''
   SELECT m.poster_time, m.id_msg, m.id_member, m.subject, m.body, m.id_topic, b.name, b.id_board, IFNULL(u.real_name, m.poster_name) AS poster_name, u.avatar, g.online_color,' 
. ($user_info['is_guest'] ? '1 AS is_read, 0 AS new_from' '
(IFNULL(lb.id_msg, 0) >= b.id_msg_updated) AS is_read,
IFNULL(lb.id_msg, -1) + 1 AS new_from'
) . '
   FROM {db_prefix}messages AS m
   LEFT JOIN {db_prefix}boards AS b ON (m.id_board = b.id_board)
   LEFT JOIN {db_prefix}members AS u ON (m.id_member = u.id_member)' 
. ($user_info['is_guest'] ? '' '
   LEFT JOIN {db_prefix}log_boards AS lb ON (lb.id_board = b.id_board AND lb.id_member = {int:current_member})'
) . '
   LEFT JOIN {db_prefix}membergroups AS g ON (g.id_group = CASE WHEN u.id_group = 0 THEN u.id_post_group ELSE u.id_group END)
   ' 
. (!$user_info['is_guest'] ? '
LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = m.id_topic AND lt.id_member = ' 
$user_info['id'] . ')
LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = b.id_board AND lmr.id_member = ' 
$user_info['id'] . ')' '') . '   
   WHERE m.approved=1'   
. (empty($exclude_boards) ? '' '
AND b.id_board NOT IN ({array_int:exclude_boards})'
) . ' AND {query_see_board}
   ORDER BY m.id_msg DESC
   LIMIT ' 
$limit
array(
'exclude_boards' => empty($exclude_boards) ? '' $exclude_boards,
'current_member' => $user_info['id'],
)   
   );
$posts = array();
while (
$row_posts $smcFunc['db_fetch_assoc']($posts_result))
{

      global 
$memberContext;
      
loadMemberData($row_posts['id_member']);
      
loadMemberContext($row_posts['id_member']);

   
$posts[] = array(
  'id' => $row_posts['id_member'],
      
'username' => '<a style="color: ' $row_posts['online_color'] . ';" href="' $scripturl '?action=profile;u=' $row_posts['id_member'] . '">' $row_posts['poster_name'] . '</a>',
      
'subject' => '<a style="font-weight: bold;" title="' $txt['board'] . ':&nbsp;' $row_posts['name'] .'" href="' $scripturl '?topic=' $row_posts['id_topic'] . '.msg' $row_posts['id_msg'] . ';topicseen#new">' $row_posts['subject'] . '</a>',
      
'body' => $row_posts['body'],
  'avatar' => $row_posts['avatar'] == '' $memberContext[$row_posts['id_member']]['avatar']['href'] : (stristr($row_posts['avatar'], 'http://') ? $row_posts['avatar'] : $modSettings['avatar_url'] . '/' $row_posts['avatar']),
  'board' => $row_posts['name'],  
  'time' => timeformat($row_posts['poster_time']),
  'new' => !empty($row_posts['is_read']),
      
'subject_new' => $scripturl '?topic=' $row_posts['id_topic'] . '.msg' $row_posts['id_msg'] . ';topicseen#new'
   
);
}
$smcFunc['db_free_result']($posts_result);

}

//Finally the Output

//Scrolling xD
if ($scrolling == 1)
echo 
'<div style="overflow: hidden;"><marquee height=' $height ' behavior="scroll" direction="up" scrollamount="' $speed '" onmouseover="this.stop()" onmouseout="this.start()">';

if (
$scrollbar == 1)
echo 
'<div style="height:' $height '; overflow-y: scroll; overflow-x: hidden;">';

foreach (
$posts as $post) {

// Lets fix the BBCode bug and Strip the Text
$content1 str_replace("[""<"$post['body']);
$content2 str_replace("]"">"$content1); 
$content3 strip_tags($content2);
$preview substr ($content3,0,$number);

echo
'<table>
<tr>
<td style="width: 40px;">
<img src="' 
$post['avatar'] .'" alt="" width="40px" height="40px" />
</td>
<td>
$post['subject'];

if (!$post['new'] && $context['user']['is_logged'])
echo '&nbsp;<a href=' $post['subject_new'] . '><img src="'$settings['images_url'], '/'$context['user']['language'], '/new.gif" alt="new" border="0" /></a>';

echo '<br />
<small>' 
$txt['by'] . '&nbsp;' $post['username'] . '&nbsp;|&nbsp;' $post['time'] .'</small>
</td>
</tr>
</table>'
;

if ($htmlspecialcharacters) {
echo htmlspecialchars($previewENT_NOQUOTES"UTF-8") . '...';
} else {
echo $preview '...';
}

echo 
'<hr />';
}
        
//Scrolling xD
if ($scrollbar == 1)
echo 
'</div>'

if (
$scrolling == 1)
echo 
'</marquee></div>';
?>

Anyone having a problem with the original and getting unidentified poster_name errors, then use the code in the above quote, works flawlessly :)
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: ♦ Ninja ZX-10RR ♦ on January 15, 2017, 01:38:49 PM
After the 2.0.13 update I was able to edit the opening post again, and updated the code to the one provided by GeorG. Thanks!
(Will add info later, in a hurry right now)

EDIT: updated.
Title: Re: [Block] Recent Topics/Posts with Post Preview!
Post by: owenenene on January 23, 2017, 09:59:16 AM
Found a little bug.

The topic / message settings does not work, whatever the setting is, it displays the messages.

$topics_posts = 1;      // TOPICS - 1 | MESSAGES - 2

From my understanding, the "1" should display recent topics created, and the "2" should display all messages (eg. topic replies, topic first posts, etc.). But 1 and 2 just display all and any posts on the forum.


Hey, I'm after this same mod but one which only shows recent topics, and the first message of that topic. Not the recent replies of that topic. Make sense? :s

Edit: i tried the "ORDER BY t.id_topic DESC", it works but it displays the most recent posts name instead of the topic authors name :(
SimplePortal 2.3.8 © 2008-2024, SimplePortal