Main Menu
collapse

Simple Portal Archived Forum

This is an Archive Forum.

The content in this forum may be out-of-date or have been superseded by newer information, and links in forum pages to other sites may not work.
This forum contains archives for future reference.

Visit our thread at Simple Machines Forum for current support.

SMF 2.1 users: EhPortal is a ported version of Simple Portal specifically designed for the SMF 2.1 branch.
Please visit web-develop.ca to download EhPortal and for its support.

User Info

Welcome Guest.
Please log in.

Who's Online

  • Dot Guests: 1132
  • Dot Hidden: 0
  • Dot Users: 0

There aren't any users online.

Recent Posts

Adding Forums Button to Nav bar by jirapon
[August 01, 2019, 09:07:12 AM]


Re: Board Icons by ♦ Ninja ZX-10RR ♦
[July 30, 2019, 04:03:41 PM]


MOVED: Czech translation???? by ♦ Ninja ZX-10RR ♦
[July 30, 2019, 03:04:51 PM]


Board Icons by jirapon
[July 30, 2019, 07:28:44 AM]


Re: Thankyou Simpleportal, by ♦ Ninja ZX-10RR ♦
[July 29, 2019, 09:41:29 AM]


Installation errors? Mod incompatibilities? Upgrade problems? Make your way over to the Install and Upgrade Support board for all your solutions!

recentPosts

Started by tibaba, March 23, 2009, 05:57:59 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

tibaba

Hello,

First, sorry for my bad english.

I need some help with the Recent Posts block.

Actually, it only display the icone, subject, and board, name of writer and date


I'd like it to appear part of the message ( 200 character for exemple) in this block. What can I do for that ?

Thanks in advance.

( I use SMF 2.0 RC1 + SP 2.1.1)

tibaba

After many try, I found I can modify this in Sportal2.php.


I must add $post[preview] to show content of message, but my problem is where ??? I want a return after the topic name.



Quoteif (empty($posts))
      return $posts;

   echo '
      <table border="0" width="100%" class="ssi_table">';
   foreach ($posts as $post)
      echo '
         <tr>
            <td align="center" valign="middle" nowrap="nowrap">
            ', $post['icon'], '   
            </td>
            <td valign="top" width="%100">
               <a href="', $post['href'], '">', $post['subject'], '</a>
               ', $post['new'] ? '' : '<a href="' . $scripturl . '?topic=' . $post['topic'] . '.msg' . $post['new_from'] . ';topicseen#new"><img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/new.gif" alt="' . $txt['new'] . '" border="0" /></a>', '<br />[', $post['board']['link'], ']
            </td>
            <td align="right" nowrap="nowrap">
               ', $post['poster']['link'], '<br />', $post['time'], '
            </td>
         </tr>';
   echo '
      </table>';

}

Nathaniel

The code below is an edited version of the Board News Block, so that it shows the most recent posts. That should do most of the stuff that you want, I can edit it some more if necessary.

You can change the "$limit = 5;" and "$length = 200;" values to change the number of topics shown and the maximum length of each message respectively.

Create a new PHP block and then put the code below into it:
global $scripturl, $txt, $settings, $modSettings, $context;
global $smcFunc, $return, $color_profile;

loadLanguage('Stats');

$limit = 5;
$length = 200;

// Load the message icons - the usual suspects.
$stable_icons = array('xx', 'thumbup', 'thumbdown', 'exclamation', 'question', 'lamp', 'smiley', 'angry', 'cheesy', 'grin', 'sad', 'wink', 'moved', 'recycled', 'wireless');
$icon_sources = array();
foreach ($stable_icons as $icon)
$icon_sources[$icon] = 'images_url';

// Find the post ids.
$request = $smcFunc['db_query']('', '
SELECT id_first_msg
FROM {db_prefix}topics' . ($modSettings['postmod_active'] ? '
WHERE approved = {int:is_approved}' : '') . '
ORDER BY id_first_msg DESC
LIMIT ' . $limit,
array(
'is_approved' => 1,
)
);
$posts = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
$posts[] = $row['id_first_msg'];
$smcFunc['db_free_result']($request);

if (empty($posts))
return array();

// Find the posts.
$request = $smcFunc['db_query']('', '
SELECT
m.icon, m.subject, m.body, IFNULL(mem.real_name, m.poster_name) AS poster_name, m.poster_time,
t.num_replies, t.id_topic, m.id_member, m.smileys_enabled, m.id_msg, t.locked, mem.avatar,
a.id_attach, a.attachment_type, a.filename, t.num_views
FROM {db_prefix}topics AS t
INNER JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_first_msg)
LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
LEFT JOIN {db_prefix}attachments AS a ON (a.id_member = m.id_member)
WHERE t.id_first_msg IN ({array_int:post_list})
ORDER BY t.id_first_msg DESC
LIMIT ' . count($posts),
array(
'post_list' => $posts,
)
);
$return = array();
$colorids = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
{
//on html replace the length... to prevent style errors... normal only admin can use this so this is the admin fault! Boardnews
$oldlength = $length;
if(stripos($row['body'], '[html]') !== false) {
$length = strrpos(strtolower($row['body']), '[/html]')+7;
}

// If we want to limit the length of the post.
if (!empty($length) && $smcFunc['strlen']($row['body']) > $length)
{
$row['body'] = $smcFunc['substr']($row['body'], 0, $length);

// The first space or line break. (<br />, etc.)
$cutoff = max(strrpos($row['body'], ' '), strrpos($row['body'], '<'));

if ($cutoff !== false)
$row['body'] = $smcFunc['substr']($row['body'], 0, $cutoff);
$row['body'] .= '...';
}

//So is there a unclosed bbc near the end try to truncate them
if(strrpos($row['body'], '[') > strrpos($row['body'], ']')) {
$row['body'] = $smcFunc['substr']($row['body'], 0, strrpos($row['body'], '['));
$row['body'] .= '...';
}

$row['body'] = parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']);

//Fix the the html fix for admins back to an normal way =).
if($oldlength != $length)
$length = $oldlength;

if ($modSettings['avatar_action_too_large'] == 'option_html_resize' || $modSettings['avatar_action_too_large'] == 'option_js_resize')
{
$avatar_width = !empty($modSettings['avatar_max_width_external']) ? ' width="' . $modSettings['avatar_max_width_external'] . '"' : '';
$avatar_height = !empty($modSettings['avatar_max_height_external']) ? ' height="' . $modSettings['avatar_max_height_external'] . '"' : '';
}
else
{
$avatar_width = '';
$avatar_height = '';
}

// Check that this message icon is there...
if (empty($modSettings['messageIconChecks_disable']) && !isset($icon_sources[$row['icon']]))
$icon_sources[$row['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['icon'] . '.gif') ? 'images_url' : 'default_images_url';

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

//Collect the color ids :)
$colorids[$row['id_member']] = $row['id_member'];

$return[] = array(
'id' => $row['id_topic'],
'message_id' => $row['id_msg'],
'icon' => '<img src="' . $settings[$icon_sources[$row['icon']]] . '/post/' . $row['icon'] . '.gif" align="middle" alt="' . $row['icon'] . '" border="0" />',
'subject' => $row['subject'],
'time' => timeformat($row['poster_time']),
'timestamp' => forum_time(true, $row['poster_time']),
'timeyear' => timeformat($row['poster_time'], '%d %b %y'),
'timeday' => timeformat($row['poster_time'], '%H:%M:%S'),
'views' => $row['num_views'],
'body' => $row['body'],
'href' => $scripturl . '?topic=' . $row['id_topic'] . '.0',
'link' => '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['num_replies'] . ' ' . ($row['num_replies'] == 1 ? $txt['ssi_comment'] : $txt['ssi_comments']) . '</a>',
'replies' => $row['num_replies'],
'new_comment' => !empty($row['locked']) ? '' : '| <a href="' . $scripturl . '?action=post;topic=' . $row['id_topic'] . '.' . $row['num_replies'] . '">' . $txt['ssi_write_comment'] . '</a>',
'poster' => array(
'id' => $row['id_member'],
'name' => $row['poster_name'],
'href' => !empty($row['id_member']) ? $scripturl . '?action=profile;u=' . $row['id_member'] : '',
'link' => !empty($row['id_member']) ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['poster_name'] . '</a>' : $row['poster_name']
),
'locked' => !empty($row['locked']),
'is_last' => false,
);
}
$smcFunc['db_free_result']($request);

if (empty($return))
return $return;

$return[count($return) - 1]['is_last'] = true;

//Give some colors to the nice poster links :)
if(!empty($colorids) && sp_loadColors($colorids) !== false)
foreach($return as $k => $p)
if(!empty($color_profile[$p['poster']['id']]['link']))
$return[$k]['poster']['link'] = $color_profile[$p['poster']['id']]['link'];

foreach ($return as $news)
{
echo '
<div class="tborder">
<table class="bordercolor" cellspacing="0" width="100%">
<tr class="catbg">
<td valign="middle">', $news['icon'], '</td>
<td valign="middle" width="100%" style="padding: 5px;"><a href="', $news['href'], '" >', $news['subject'], '</a> | ', $news['timeyear'], '</td>
</tr>
<tr class="windowbg">
<td style="padding: 5px;"colspan="2">
<div class="post">', $news['body'], '<br/><br/>
</div>
</td>
</tr>
</table>
</div>
<br />';
}
SMF Friend (Former Support Specialist) | SimplePortal DeveloperMy SMF Mods | SimplePortal"Quis custodiet ipsos custodes?" - Who will Guard the Guards?Please don't send me ANY support related PMs. I will just delete them.

tibaba

#3
Thanks so much LHVWB   ;)

Working like a charm, but I'd like to change two small things. ( if possible of course  :nervous-happy: )

The first thing :

- I would add the name of the person who wrote the message to the right of the date. ( I already changed $news['timeyear'] to $news['time'])

   
Second thing, a little more complicated :

For example, I would like to have the last 30 messages, but divided into 3 pages of 10 messages. There should be at the bottom a link to other pages.


I put a picture to show what it might look.


   
Thank you in advance, it's very nice to have already done this. And once again sorry for my English


EDIT : This code show the last topic , but not the last message. For exemple, if I reply in a topic, it doesn't show in the list.
Can we change this ? Thanks.