Customization > Blocks and Modifications

[Block] Recent Topics/Posts with Post Preview!

<< < (3/39) > >>

Blue:
Glad you like it ;)

amko_sa:
When I activate recent php block, I have to many xhtml validation errors.
Can you correct that errors?

Blue:
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 :(

amko_sa:
Thank you blue :)

Blue:
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: ---<?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>
';
}
?>
--- End code ---

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version