Welcome, Guest. Please login or register.
Did you miss your activation email?
April 18, 2014, 05:42:02 PM

Login with username, password and session length

Last 25 Topics



Note:  Clicking the link above will open a new tab in your browser !!

Recent

Members
  • Total Members: 3398
  • Latest: dekrelo
Stats
  • Total Posts: 173425
  • Total Topics: 19802
  • Online Today: 87
  • Online Ever: 278
  • (October 31, 2012, 08:52:18 AM)
Users Online
Users: 0
Guests: 64
Total: 64

Donate

Help us to keep the support site
going, Please consider a small donation.

Thank you
Please read the Posting Guidelines

Author Topic: [Block] Recent TOPICS table with hover over previews.  (Read 4508 times)

0 Members and 1 Guest are viewing this topic.

Offline Freddy

  • Moderator
  • *
  • Posts: 1546
    • AiDreams
[Block] Recent TOPICS table with hover over previews.
« on: January 03, 2010, 01:01:43 AM »
Name of Snippet: Recent TOPICS table with hover over previews.
SMF/TP versions tested:
  • SMF 1.1.11; TinyPortal v1.0 beta 4
  • SMF 2.0 RC3, TinyPortal 1.0 beta 5-1
Block Type: PHP
Author: freddy888, mrcare and digger at SMF
Link to Discussion: Click here...
Requirements : This block uses the NiceToolTips MOD at SMF in combination with the block code below.  So you will need to install that mod too in order for this to work.

Note : sometimes bbc code may not be handled correctly - this is something for the NiceToolTips maker to work on - so try requesting that they work on that.

Description: This will show as many recent topics as you decide in a formatted table.  There are now a number of variations on this script, all of which can be found below in this topic.

This code excludes the recycle boards, omits private boards that a user cannot see and uses the NiceToolTips settings to limit the number of characters shown.
« Last Edit: April 23, 2010, 09:17:44 AM by freddy888 »

Offline Freddy

  • Moderator
  • *
  • Posts: 1546
    • AiDreams
Re: [Block] Recent TOPICS table with hover over previews.
« Reply #1 on: January 03, 2010, 01:02:23 AM »
Code for SMF 1

A simple table of recent topics with hover over.

Code: [Select]
// *********************************************************************
// A PHP block by Freddy888 and MrCare
// Used alongside the NiceToolTips mod, will show
// recent topics in a table with tool tip previews.

// @SMF Mods : http://custom.simplemachines.org/mods/index.php?mod=2115
// @Tiny Portal : http://www.tinyportal.net/index.php?topic=31642

// This version : 3 Jan 2010
// *********************************************************************

// Cofiguration, set the number of posts to show:

$num_recent = 8;

// Config end.


global $scripturl, $settings, $modSettings, $db_prefix, $user_info, $ID_MEMBER;

// First get all the NiceToolTip javascript in place if it's needed.
// The javascript is not needed when we are in a board as the NiceToolTip module
// will already have loaded it.  We just need to add it if we are elsewhere...

// So add the code if we are not in a board
// OR When viewing a topic the board is also set,
// so we need to add the javascript then too...

if (!isset($_GET['board']) || isset($_GET['topic']))
echo '
<style type="text/css">
.nice_tooltip_fgclass {
background-color: ' . $modSettings['NiceTooltips_FGCOLOR'] . ';
opacity: ' . $modSettings['NiceTooltips_OPACITY'] / 100 . ';
}
.nice_tooltip_bgclass {
background-color: ' . $modSettings['NiceTooltips_BGCOLOR'] . ';
opacity: ' . $modSettings['NiceTooltips_OPACITY'] / 100 . ';
}
</style>

<script language="JavaScript" type="text/javascript" src="' . $settings['default_theme_url'] . (!empty($modSettings['NiceTooltips_scripturl']) ? '/' . $modSettings['NiceTooltips_scripturl'] : '') . '/overlib_mini.js"></script>

<script language="JavaScript" type="text/javascript" src="' . $settings['default_theme_url'] . (!empty($modSettings['NiceTooltips_scripturl']) ? '/' . $modSettings['NiceTooltips_scripturl'] : '') . '/overlib_adaptive_width.js"></script>
';


// leave out the recycle board, if any
if(isset($modSettings['recycle_board']))
$exclude = array($modSettings['recycle_board']);
else
$exclude = array();


if ($exclude === null && !empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0)
$exclude = array($modSettings['recycle_board']);
else
$exclude = empty($exclude) ? array() : $exclude;


// Find all the posts in distinct topics.  Newer ones will have higher IDs.
// Stripped down from SSI.php ssi_recentTopics() function.

$request = db_query("
SELECT
m.posterTime, ms.subject, m.ID_TOPIC, m.ID_MEMBER, m.ID_MSG, b.ID_BOARD, b.name AS bName,
IFNULL(mem.realName, m.posterName) AS posterName, " . ($user_info['is_guest'] ? '1 AS isRead, 0 AS new_from' : '
IFNULL(lt.ID_MSG, IFNULL(lmr.ID_MSG, 0)) >= m.ID_MSG_MODIFIED AS isRead,
IFNULL(lt.ID_MSG, IFNULL(lmr.ID_MSG, -1)) + 1 AS new_from') . ",
LEFT(m.body, ". (!empty($modSettings['NiceTooltips_lenght']) ? $modSettings['NiceTooltips_lenght'] : 384) .") AS body, m.smileysEnabled
FROM ({$db_prefix}messages AS m, {$db_prefix}topics AS t, {$db_prefix}boards AS b, {$db_prefix}messages AS ms)
LEFT JOIN {$db_prefix}members AS mem ON (mem.ID_MEMBER = m.ID_MEMBER)" . (!$user_info['is_guest'] ? "
LEFT JOIN {$db_prefix}log_topics AS lt ON (lt.ID_TOPIC = t.ID_TOPIC AND lt.ID_MEMBER = $ID_MEMBER)
LEFT JOIN {$db_prefix}log_mark_read AS lmr ON (lmr.ID_BOARD = b.ID_BOARD AND lmr.ID_MEMBER = $ID_MEMBER)" : '') . "
WHERE t.ID_LAST_MSG >= " . ($modSettings['maxMsgID'] - 35 * min($num_recent, 5)) . "
AND t.ID_LAST_MSG = m.ID_MSG
AND b.ID_BOARD = t.ID_BOARD" . (empty($exclude) ? '' : "
AND b.ID_BOARD NOT IN (" . implode(', ', $exclude) . ")") . "
AND $user_info[query_see_board]
AND ms.ID_MSG = t.ID_FIRST_MSG
ORDER BY t.ID_LAST_MSG DESC
LIMIT $num_recent", __FILE__, __LINE__);

$posts = array();

while ($row = mysql_fetch_assoc($request))
{
// Build the array.
$posts[] = array(
'board' => array(
'link' => '<a href="' . $scripturl . '?board=' . $row['ID_BOARD'] . '.0">' . $row['bName'] . '</a>'
),
'topic' => $row['ID_TOPIC'],
'poster' => array(
'link' => empty($row['ID_MEMBER']) ? $row['posterName'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] . '">' . $row['posterName'] . '</a>'
),
'subject' => $row['subject'],
'preview' => $row['body'],
'time' => timeformat($row['posterTime']),
'href' => $scripturl . '?topic=' . $row['ID_TOPIC'] . '.msg' . $row['ID_MSG'] . ';topicseen#new',
'link' => '<a href="' . $scripturl . '?topic=' . $row['ID_TOPIC'] . '.msg' . $row['ID_MSG'] . '#new">' . $row['subject'] . '</a>',
'new' => !empty($row['isRead']),
);
}

mysql_free_result($request);


// Now for the output...

echo '
<table border="0" width="100%" cellspacing="1" cellpadding="3" class="bordercolor">
<tr class="catbg3">
<td align="center">Subject</td>
<td align="center">Board</td>
<td align="center">Member</td>
<td align="center">Date & Time</td>
</tr>';

$bg=false;

foreach ($posts as $topic)
{
// Generate the popup.
$popup = NiceTooltip($topic['preview'], $topic['subject']);

echo '
<tr class="windowbg' , $bg ? '2' : '' , '">';

$bg = !$bg;
   
echo '
<td valign="middle">
<a href="' , $topic['href'] , '"' , $popup , '>' , $topic['subject'] , '</a>';

    // Is this topic new? (assuming they are logged in!)
if (!$topic['new'] && $context['user']['is_logged'])
echo '
<a href="', $scripturl, '?topic=', $topic['topic'], '.from', $topic['time'], '#new"><img src="', $settings['images_url'], '/', $context['user']['language'], '/new.gif" alt="New', $txt[302], '" border="0" align="right", valign="absmiddle" /></a>';

echo '
</td>
<td valign="middle" >', $topic['board']['link'], '</td>';

echo '
<td valign="middle" >', $topic['poster']['link'], '</td>
<td valign="middle" >';

if ($settings['images_url'] != $settings['theme_url'] . '/images' || file_exists($settings['theme_dir'] . '/images/icons/last_post.gif'))
echo '
<a href="', $topic['href'], '"><img src="', $settings['images_url'], '/icons/last_post.gif" alt="', $txt[111], '" title="', $txt[111], '" border="0" style="float: right;" /></a>';

echo '
<span class="smalltext">', $topic['time'], '</span>
</td>
</tr>';
}

echo '
</table>';
« Last Edit: April 27, 2010, 07:33:32 AM by freddy888 »

Offline Freddy

  • Moderator
  • *
  • Posts: 1546
    • AiDreams
Re: [Block] Recent TOPICS table with hover over previews.
« Reply #2 on: April 14, 2010, 02:50:42 AM »
Code for SMF 2

This new version also shows the message icon, number of views and replies.

Code: [Select]
// *********************************************************************
// A PHP block by Freddy888 and MrCare
// !!Modified to show icon, number of views and replies.!!
// Used alongside the NiceToolTips mod, will show
// recent topics in a table with tool tip previews.

// @SMF Mods : http://custom.simplemachines.org/mods/index.php?mod=2115
// @Tiny Portal : http://www.tinyportal.net/index.php?topic=31642

// This version : 13 April 2010 Update to work with SMF2RC3
// Note that this version is ONLY for SMF2.
// *********************************************************************

// Configuration, set the number of posts to show:

$num_recent = 8;

// Config end.


global $scripturl, $settings, $modSettings, $db_prefix, $user_info;

// First get all the NiceToolTip javascript in place if it's needed.
// The javascript is not needed when we are in a board as the NiceToolTip module
// will already have loaded it.  We just need to add it if we are elsewhere...

// So add the code if we are not in a board
// OR When viewing a topic the board is also set,
// so we need to add the javascript then too...

if (!isset($_GET['board']) || isset($_GET['topic']))
echo '
<style type="text/css">
.nice_tooltip_fgclass {
background-color: ' . $modSettings['NiceTooltips_FGCOLOR'] . ';
opacity: ' . $modSettings['NiceTooltips_OPACITY'] / 100 . ';
}
.nice_tooltip_bgclass {
background-color: ' . $modSettings['NiceTooltips_BGCOLOR'] . ';
opacity: ' . $modSettings['NiceTooltips_OPACITY'] / 100 . ';
}
</style>

<script language="JavaScript" type="text/javascript" src="' . $settings['default_theme_url'] . (!empty($modSettings['NiceTooltips_scripturl']) ? '/' . $modSettings['NiceTooltips_scripturl'] : '') . '/overlib_mini.js"></script>

<script language="JavaScript" type="text/javascript" src="' . $settings['default_theme_url'] . (!empty($modSettings['NiceTooltips_scripturl']) ? '/' . $modSettings['NiceTooltips_scripturl'] : '') . '/overlib_adaptive_width.js"></script>
';


// leave out the recycle board, if any
if(isset($modSettings['recycle_board']))
$exclude = array($modSettings['recycle_board']);
else
$exclude = array();

   
if ($exclude === null && !empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0)
$exclude = array($modSettings['recycle_board']);
else
$exclude = empty($exclude) ? array() : $exclude;

// Icons...
$stable_icons = array('xx', 'thumbup', 'thumbdown', 'exclamation', 'question', 'lamp', 'smiley', 'angry', 'cheesy', 'grin', 'sad', 'wink', 'moved', 'recycled', 'wireless', 'clip');
$icon_sources = array();
foreach ($stable_icons as $icon)
$icon_sources[$icon] = 'images_url';

// Find all the posts in distinct topics.  Newer ones will have higher IDs.
// Stripped down from SSI.php ssi_recentTopics() function.

$request = tp_query("
SELECT
m.poster_time, ms.subject, m.id_topic, m.id_member, m.id_msg, b.id_board, b.name AS board_name, t.num_replies, t.num_views,
IFNULL(mem.real_name, m.poster_name) AS poster_name, " . ($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') . ",
LEFT(m.body, ". (!empty($modSettings['NiceTooltips_lenght']) ? $modSettings['NiceTooltips_lenght'] : 384) .") AS body, m.smileys_enabled, m.icon
FROM ({$db_prefix}messages AS m, {$db_prefix}topics AS t, {$db_prefix}boards AS b, {$db_prefix}messages AS ms)
LEFT JOIN {$db_prefix}members AS mem ON (mem.id_member = m.id_member)" . (!$user_info['is_guest'] ? "
LEFT JOIN {$db_prefix}log_topics AS lt ON (lt.id_topic = t.id_topic AND lt.id_member = {$context['user']['id']})
LEFT JOIN {$db_prefix}log_mark_read AS lmr ON (lmr.id_board = b.id_board AND lmr.id_member = {$context['user']['id']})" : '') . "
WHERE t.id_last_msg >= " . ($modSettings['maxMsgID'] - 35 * min($num_recent, 5)) . "
AND t.id_last_msg = m.id_msg
AND b.id_board = t.id_board" . (empty($exclude) ? '' : "
AND b.id_board NOT IN (" . implode(', ', $exclude) . ")") . "
AND $user_info[query_see_board]
AND ms.id_msg = t.id_first_msg
ORDER BY t.id_last_msg DESC
LIMIT $num_recent", __FILE__, __LINE__);


$posts = array();

while ($row = tpdb_fetch_assoc($request))
{
// Build the array.
$posts[] = array(
'board' => array(
'link' => '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['board_name'] . '</a>'
),
'topic' => $row['id_topic'],
'poster' => array(
'link' => empty($row['id_member']) ? $row['poster_name'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['poster_name'] . '</a>'
),
'subject' => $row['subject'],
'preview' => $row['body'],
'time' => timeformat($row['poster_time']),
'href' => $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . ';topicseen#new',
'link' => '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#new">' . $row['subject'] . '</a>',
'new' => !empty($row['is_read']),
'icon' => '<img src="' . $settings[$icon_sources[$row['icon']]] . '/post/' . $row['icon'] . '.gif" align="middle" alt="' . $row['icon'] . '" border="0" />',
'viewsreplies' => $row['num_views'] . '/' . $row['num_replies'],
);
}

tpdb_free_result($request);


// Now for the output...

echo '
<table border="0" width="100%" cellspacing="1" cellpadding="3" class="bordercolor">
<tr class="titlebg">
<td align="center" colspan="2">Subject</td>
<td align="center">Board</td>
<td align="center">Views/Replies</td>
<td align="center">Member</td>
<td align="center">Date & Time</td>
</tr>';

$bg=false;

foreach ($posts as $topic)
{
// Generate the popup.
$popup = NiceTooltip($topic['preview'], $topic['subject']);

echo '
<tr class="windowbg' , $bg ? '2' : '' , '">';

$bg = !$bg;
   
echo '
<td valign="middle">
' , $topic['icon'] , '
</td>
<td>
<a href="' , $topic['href'] , '"' , $popup , '>' , $topic['subject'] , '</a>';

    // Is this topic new? (assuming they are logged in!)
if (!$topic['new'] && $context['user']['is_logged'])
echo '
<a href="', $scripturl, '?topic=', $topic['topic'], '.from', $topic['time'], '#new"><img src="', $settings['images_url'], '/', $context['user']['language'], '/new.gif" alt="', $txt['new'], '" border="0" align="right", valign="absmiddle" /></a>';

echo '
</td>
<td valign="middle">' , $topic['board']['link'], '</td>';

echo '
<td valign="middle" align="center">' , $topic['viewsreplies'] , '</td>';

echo '
<td valign="middle" >', $topic['poster']['link'], '</td>
<td valign="middle" >';

if ($settings['images_url'] != $settings['theme_url'] . '/images' || file_exists($settings['theme_dir'] . '/images/icons/last_post.gif'))
echo '
<a href="', $topic['href'], '"><img src="', $settings['images_url'], '/icons/last_post.gif" alt="', $txt['last_post'], '" title="', $txt['last_post'], '" border="0" style="float: right;" /></a>';

echo '
<span class="smalltext">', $topic['time'], '</span>
</td>
</tr>';
}

echo '
</table>';

========================================================


Thanks to IchBin - SMF2 TP1 :

Code: [Select]
// *********************************************************************
// A PHP block by Freddy888 and MrCare
// !!Modified to show icon, number of views and replies.!!
// Used alongside the NiceToolTips mod, will show
// recent topics in a table with tool tip previews.

// @SMF Mods : http://custom.simplemachines.org/mods/index.php?mod=2115
// @Tiny Portal : http://www.tinyportal.net/index.php?topic=31642

// Note that this version is ONLY for SMF2.
// *********************************************************************

// Configuration, set the number of posts to show:
   
$num_recent = 8;
   
// Config end.


global $scripturl, $settings, $modSettings, $db_prefix, $user_info, $smcFunc, $txt;

// First get all the NiceToolTip javascript in place if it's needed.
// The javascript is not needed when we are in a board as the NiceToolTip module
// will already have loaded it.  We just need to add it if we are elsewhere...

// So add the code if we are not in a board
// OR When viewing a topic the board is also set,
// so we need to add the javascript then too...
   
if (!isset($_GET['board']) || isset($_GET['topic']))
   echo '
         <style type="text/css">
         .nice_tooltip_fgclass {
         background-color: ' . $modSettings['NiceTooltips_FGCOLOR'] . ';
         opacity: ' . $modSettings['NiceTooltips_OPACITY'] / 100 . ';
         }
         .nice_tooltip_bgclass {
         background-color: ' . $modSettings['NiceTooltips_BGCOLOR'] . ';
         opacity: ' . $modSettings['NiceTooltips_OPACITY'] / 100 . ';
         }
         </style>

         <script language="JavaScript" type="text/javascript" src="' . $settings['default_theme_url'] . (!empty($modSettings['NiceTooltips_scripturl']) ? '/' . $modSettings['NiceTooltips_scripturl'] : '') .   '/overlib_mini.js"></script>

         <script language="JavaScript" type="text/javascript" src="' . $settings['default_theme_url'] . (!empty($modSettings['NiceTooltips_scripturl']) ? '/' . $modSettings['NiceTooltips_scripturl'] : '') . '/overlib_adaptive_width.js"></script>
';


// leave out the recycle board, if any
if(isset($modSettings['recycle_board']))
   $exclude = array($modSettings['recycle_board']);
else
   $exclude = array();

   
if ($exclude === null && !empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0)
   $exclude = array($modSettings['recycle_board']);
else
   $exclude = empty($exclude) ? array() : $exclude;   

// Icons...   
$stable_icons = array('xx', 'thumbup', 'thumbdown', 'exclamation', 'question', 'lamp', 'smiley', 'angry', 'cheesy', 'grin', 'sad', 'wink', 'moved', 'recycled', 'wireless', 'clip');
$icon_sources = array();
foreach ($stable_icons as $icon)
   $icon_sources[$icon] = 'images_url';
     
// Find all the posts in distinct topics.  Newer ones will have higher IDs.
// Stripped down from SSI.php ssi_recentTopics() function.

$request = $smcFunc['db_query']('', '
   SELECT
      m.poster_time, ms.subject, m.id_topic, m.id_member, m.id_msg, b.id_board, b.name AS board_name, t.num_replies, t.num_views,
      IFNULL(mem.real_name, m.poster_name) AS poster_name, ' . ($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') . ',
      LEFT(m.body, '. (!empty($modSettings['NiceTooltips_lenght']) ? $modSettings['NiceTooltips_lenght'] : 384) .') AS body, m.smileys_enabled, m.icon
   FROM ({db_prefix}messages AS m, {db_prefix}topics AS t, {db_prefix}boards AS b, {db_prefix}messages AS ms)
      LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)' . (!$user_info['is_guest'] ? '
      LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = t.id_topic AND lt.id_member = '.$context['user']['id'].')
      LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = b.id_board AND lmr.id_member = '.$context['user']['id'].')' : '') . '
   WHERE t.id_last_msg >= ' . ($modSettings['maxMsgID'] - 35 * min($num_recent, 5)) . '
      AND t.id_last_msg = m.id_msg
      AND b.id_board = t.id_board' . (empty($exclude) ? '' : '
      AND b.id_board NOT IN ({array_int:exclude})') . '
      AND {query_see_board}
      AND ms.id_msg = t.id_first_msg
   ORDER BY t.id_last_msg DESC
   LIMIT {int:num_recent}',
   array('exclude' => $exclude, 'num_recent' => $num_recent)
);
 
$posts = array();

while ($row = $smcFunc['db_fetch_assoc']($request))
{
   // Build the array.
   $posts[] = array(
      'board' => array(
         'link' => '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['board_name'] . '</a>'
      ),
      'topic' => $row['id_topic'],
      'poster' => array(
         'link' => empty($row['id_member']) ? $row['poster_name'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['poster_name'] . '</a>'
      ),
      'subject' => $row['subject'],
      'preview' => $row['body'],
      'time' => timeformat($row['poster_time']),
      'href' => $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . ';topicseen#new',
      'link' => '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#new">' . $row['subject'] . '</a>',
      'new' => !empty($row['is_read']),
      'icon' => '<img src="' . $settings[$icon_sources[$row['icon']]] . '/post/' . $row['icon'] . '.gif" align="middle" alt="' . $row['icon'] . '" border="0" />',
      'viewsreplies' => $row['num_views'] . '/' . $row['num_replies'],
   );
}

$smcFunc['db_free_result']($request);

   
// Now for the output...

echo '
   <table border="0" width="100%" cellspacing="1" cellpadding="3" class="bordercolor">
      <tr class="titlebg">
         <td align="center" colspan="2">Subject</td>
         <td align="center">Board</td>
         <td align="center">Views/Replies</td>
         <td align="center">Member</td>
         <td align="center">Date & Time</td>
      </tr>';

$bg = false;

foreach ($posts as $topic)
{
   // Generate the popup.
   $popup = NiceTooltip($topic['preview'], $topic['subject']);
   
   echo '
      <tr class="windowbg' , $bg ? '2' : '' , '">';
     
   $bg = !$bg;
   
   echo '
         <td valign="middle">
            ' , $topic['icon'] , '
         </td>
         <td>
            <a href="' , $topic['href'] , '"' , $popup , '>' , $topic['subject'] , '</a>';

    // Is this topic new? (assuming they are logged in!)
   if (!$topic['new'] && $context['user']['is_logged'])
      echo '
            <a href="', $scripturl, '?topic=', $topic['topic'], '.from', $topic['time'], '#new"><img src="', $settings['images_url'], '/', $context['user']['language'], '/new.gif" alt="', $txt['new'], '" border="0" align="right", valign="absmiddle" /></a>';
   
   echo '
         </td>
         <td valign="middle">' , $topic['board']['link'], '</td>';
   
   echo '
         <td valign="middle" align="center">' , $topic['viewsreplies'] , '</td>';
   
   echo '
         <td valign="middle" >', $topic['poster']['link'], '</td>
         <td valign="middle" >';

   if ($settings['images_url'] != $settings['theme_url'] . '/images' || file_exists($settings['theme_dir'] . '/images/icons/last_post.gif'))
      echo '
            <a href="', $topic['href'], '"><img src="', $settings['images_url'], '/icons/last_post.gif" alt="', $txt['last_post'], '" title="', $txt['last_post'], '" border="0" style="float: right;" /></a>';
   
   echo '
            <span class="smalltext">', $topic['time'], '</span>
         </td>
      </tr>';
}

echo '
   </table>';
« Last Edit: June 15, 2011, 10:22:52 AM by Freddy »

Offline Freddy

  • Moderator
  • *
  • Posts: 1546
    • AiDreams
Re: [Block] Recent TOPICS table with hover over previews.
« Reply #3 on: April 21, 2010, 08:01:24 AM »
Variation for SMF 2

This variation can show the class of the post too - eg hot topic, locked, sticky etc.

You can configure the icons it shows or set it to show no icons at all.


Code: [Select]
// *********************************************************************
// A PHP block by Freddy888 and MrCare
// !!Modified to show icon, number of views and replies.!!
// !!Modified to show or not show icon & show or not show message class!!
// Used alongside the NiceToolTips mod, will show
// recent topics in a table with tool tip previews.

// @SMF Mods : http://custom.simplemachines.org/mods/index.php?mod=2115
// @Tiny Portal : http://www.tinyportal.net/index.php?topic=31642

// This version : 18 April 2010
// Note that this version is ONLY for SMF2.
// *********************************************************************

// Configuration
 
// set the number of posts to show:
$num_recent = 8;

// Show class ?  Hot topic, locked etc.. (true or false)
$show_class_icon = true;

// Show the icon for type of message ? Lamp, thumbs up, smiley etc (true or false)
$show_message_icon = true;

// Config end.


global $scripturl, $settings, $modSettings, $db_prefix, $user_info;

// First get all the NiceToolTip javascript in place if it's needed.
// The javascript is not needed when we are in a board as the NiceToolTip module
// will already have loaded it.  We just need to add it if we are elsewhere...

// So add the code if we are not in a board
// OR When viewing a topic the board is also set,
// so we need to add the javascript then too...

if (!isset($_GET['board']) || isset($_GET['topic']))
echo '
<style type="text/css">
.nice_tooltip_fgclass {
background-color: ' . $modSettings['NiceTooltips_FGCOLOR'] . ';
opacity: ' . $modSettings['NiceTooltips_OPACITY'] / 100 . ';
}
.nice_tooltip_bgclass {
background-color: ' . $modSettings['NiceTooltips_BGCOLOR'] . ';
opacity: ' . $modSettings['NiceTooltips_OPACITY'] / 100 . ';
}
</style>

<script language="JavaScript" type="text/javascript" src="' . $settings['default_theme_url'] . (!empty($modSettings['NiceTooltips_scripturl']) ? '/' . $modSettings['NiceTooltips_scripturl'] : '') . '/overlib_mini.js"></script>

<script language="JavaScript" type="text/javascript" src="' . $settings['default_theme_url'] . (!empty($modSettings['NiceTooltips_scripturl']) ? '/' . $modSettings['NiceTooltips_scripturl'] : '') . '/overlib_adaptive_width.js"></script>
';


// leave out the recycle board, if any
if(isset($modSettings['recycle_board']))
$exclude = array($modSettings['recycle_board']);
else
$exclude = array();

   
if ($exclude === null && !empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0)
$exclude = array($modSettings['recycle_board']);
else
$exclude = empty($exclude) ? array() : $exclude;

// Icons...
$stable_icons = array('xx', 'thumbup', 'thumbdown', 'exclamation', 'question', 'lamp', 'smiley', 'angry', 'cheesy', 'grin', 'sad', 'wink', 'moved', 'recycled', 'wireless','clip');
$icon_sources = array();
foreach ($stable_icons as $icon)
$icon_sources[$icon] = 'images_url';


// Find all the posts in distinct topics.  Newer ones will have higher IDs.
// Stripped down from SSI.php ssi_recentTopics() function.

$request = tp_query("
SELECT
m.poster_time, ms.subject, m.id_topic, m.id_member, m.id_msg, b.id_board, b.name AS board_name, t.num_replies, t.num_views, t.is_sticky, t.locked, t.id_poll,
IFNULL(mem.real_name, m.poster_name) AS poster_name, " . ($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') . ",
LEFT(m.body, ". (!empty($modSettings['NiceTooltips_lenght']) ? $modSettings['NiceTooltips_lenght'] : 384) .") AS body, m.smileys_enabled, m.icon
FROM ({$db_prefix}messages AS m, {$db_prefix}topics AS t, {$db_prefix}boards AS b, {$db_prefix}messages AS ms)
LEFT JOIN {$db_prefix}members AS mem ON (mem.id_member = m.id_member)" . (!$user_info['is_guest'] ? "
LEFT JOIN {$db_prefix}log_topics AS lt ON (lt.id_topic = t.id_topic AND lt.id_member = {$context['user']['id']})
LEFT JOIN {$db_prefix}log_mark_read AS lmr ON (lmr.id_board = b.id_board AND lmr.id_member = {$context['user']['id']})" : '') . "
WHERE t.id_last_msg >= " . ($modSettings['maxMsgID'] - 35 * min($num_recent, 5)) . "
AND t.id_last_msg = m.id_msg
AND b.id_board = t.id_board" . (empty($exclude) ? '' : "
AND b.id_board NOT IN (" . implode(', ', $exclude) . ")") . "
AND $user_info[query_see_board]
AND ms.id_msg = t.id_first_msg
ORDER BY t.id_last_msg DESC
LIMIT $num_recent", __FILE__, __LINE__);


// An array to hold all the posts/new topics in.
$posts = array();

// use a counter for topics so we can track the index of the $posts array - if needed.
$topic_count = 0;

// Keeps track of topic ids found so we can see if the user posted in a topic - if needed.
$topic_ids = array();


while ($row = tpdb_fetch_assoc($request))
{
// Build the array.
$posts[] = array(
'board' => array(
'link' => '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['board_name'] . '</a>'
),
'topic' => $row['id_topic'],
'poster' => array(
'link' => empty($row['id_member']) ? $row['poster_name'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['poster_name'] . '</a>'
),
'subject' => $row['subject'],
'preview' => $row['body'],
'time' => timeformat($row['poster_time']),
'href' => $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . ';topicseen#new',
'link' => '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#new">' . $row['subject'] . '</a>',
'new' => !empty($row['is_read']),
'icon' => '<img src="' . $settings[$icon_sources[$row['icon']]] . '/post/' . $row['icon'] . '.gif" align="middle" alt="' . $row['icon'] . '" border="0" />',
'views_replies' => $row['num_views'] . '/' . $row['num_replies'],
'is_sticky' => !empty($modSettings['enableStickyTopics']) && !empty($row['is_sticky']),
'is_locked' => !empty($row['locked']),
'is_poll' => $modSettings['pollMode'] == '1' && $row['id_poll'] > 0,
'is_hot' => $row['num_replies'] >= $modSettings['hotTopicPosts'],
'is_very_hot' => $row['num_replies'] >= $modSettings['hotTopicVeryPosts'],
);

// Are we showing the icon for class of topic ?  Otherwise ignore this part as it's not needed.
if ($show_class_icon == true)
{
// Use the SMF function that works out what icon class we need to show.
determineTopicClass($posts[$topic_count]);

// Add this topic to our array of topics being found.
$topic_ids[] = $row['id_topic'];

$topic_count++;
}
}

tpdb_free_result($request);

// Again, are we showing the message/topic class icon ?  Otherwise don't bother with this bit.
if ($show_class_icon == true)
{
// See if the user posted in any of the topics found.
$request = tp_query("
SELECT id_topic
FROM {$db_prefix}messages
WHERE id_topic
IN (" . implode(', ',$topic_ids) . ")
AND id_member = {$context['user']['id']}
GROUP BY id_topic
LIMIT " . count($topic_ids), __FILE__, __LINE__);

// Now we know what topics the user posted in we can put them in an array
// and refer to it when we do the output.
$posted_in = array();

while ($row = tpdb_fetch_assoc($request))
{
$posted_in[] = $row['id_topic'];
}
tpdb_free_result($request);
}


// Now for the output...

// Set the cell span for subject depending on the number of icons we have to show.
$col_span = 1;

if ($show_class_icon == true)
$col_span++;
if ($show_message_icon == true)
$col_span++;


echo '
<table border="0" width="100%" cellspacing="1" cellpadding="3" class="bordercolor">
<tr class="titlebg">
<td align="center" colspan="' , $col_span , '">Subject</td>
<td align="center">Board</td>
<td align="center">Views/Replies</td>
<td align="center">Member</td>
<td align="center">Date & Time</td>
</tr>';

$bg=false;

foreach ($posts as $topic)
{
// Generate the popup.
$popup = NiceTooltip($topic['preview'], $topic['subject']);

echo '
<tr class="windowbg' , $bg ? '2' : '' , '">';

$bg = !$bg;
 
if ($show_class_icon == true)
echo '
<td valign="middle">
<img src="' , $settings['images_url'] , '/topic/' , (in_array($topic['topic'], $posted_in) ? 'my_' : '') , $topic['class'] , '.gif" alt="" />
</td>';

if ($show_message_icon == true)
echo '
<td valign="middle">
' , $topic['icon'] , '
</td>';

echo '
<td>
<a href="' , $topic['href'] , '"' , $popup , '>' , $topic['subject'] , '</a>';

    // Is this topic new? (assuming they are logged in!)
if (!$topic['new'] && $context['user']['is_logged'])
echo '
<a href="', $scripturl, '?topic=', $topic['topic'], '.from', $topic['time'], '#new"><img src="', $settings['images_url'], '/', $context['user']['language'], '/new.gif" alt="', $txt['new'], '" border="0" align="right", valign="absmiddle" /></a>';

echo '
</td>
<td valign="middle">' , $topic['board']['link'], '</td>';

echo '
<td valign="middle" align="center">' , $topic['views_replies'] , '</td>';

echo '
<td valign="middle" >', $topic['poster']['link'], '</td>
<td valign="middle" >';

if ($settings['images_url'] != $settings['theme_url'] . '/images' || file_exists($settings['theme_dir'] . '/images/icons/last_post.gif'))
echo '
<a href="', $topic['href'], '"><img src="', $settings['images_url'], '/icons/last_post.gif" alt="', $txt['last_post'], '" title="', $txt['last_post'], '" border="0" style="float: right;" /></a>';

echo '
<span class="smalltext">', $topic['time'], '</span>
</td>
</tr>';
}

echo '
</table>';
« Last Edit: April 27, 2010, 07:34:51 AM by freddy888 »

Offline Freddy

  • Moderator
  • *
  • Posts: 1546
    • AiDreams
Re: [Block] Recent TOPICS table with hover over previews.
« Reply #4 on: April 23, 2010, 09:11:55 AM »
Yet Another Variation for SMF 2

This version can be configured to display topics from a set number of days.  So for example you could configure it to show topics from the past 7 days.  With this version it is still possible to display x number of topics - as the 'from x days past' feature can be disabled.

Also this version introduces a sortable table using some javascript I found here...  All columns in the table can now be sorted.

Icons can still be be switched on or off.

Attached to this post is the zipped javascript file that you will need.  Unzip that and drop the sorttable.js file into your forum's ...Themes/default/scripts directory with all the other javascript.

Then add this code to a php block (or article) - it needs a wide block, it is not suitable for side panels.

Image attached shows table being sorted by topic subject.

Thanks go to BlueSteel for coming up with the new ideas :)

Code: [Select]
// *********************************************************************
// A PHP block by Freddy888 and MrCare and ideas from BlueSteel
// !!Modified to show icon, number of views and replies.!!
// !!Modified to show or not show icon & show or not show message class!!
// !!Modified to show topics from a range of days passed!!
// !!Modified to enable sortable table !!
//
// Used alongside the NiceToolTips mod, will show
// recent topics in a table with tool tip previews.
// Also requires sorttable.js which can be found at
// http://www.kryogenix.org/code/browser/sorttable/
// Drop the sorttable.js in your Themes/default/scripts directory.

// @SMF Mods (NiceToolTips) : http://custom.simplemachines.org/mods/index.php?mod=2115
// @Tiny Portal : http://www.tinyportal.net/index.php?topic=31642

// This version : 23 April 2010
// Note that this version is ONLY for SMF2.
// *********************************************************************

// Configuration
 
// Set the number of posts to show..
$num_recent = 8;

// Alternatively set here a range of days passed.
// eg , 7 will get all the topics in the past 7 days.
// This will over-ride $num_recent above.  Set to 0 to disable.
$num_days = 7;

// Show class ?  Hot topic, locked etc.. (true or false)
$show_class_icon = true;

// Show the icon for type of message ? Lamp, thumbs up, smiley etc (true or false)
$show_message_icon = true;

// Config end.


global $scripturl, $settings, $modSettings, $db_prefix, $user_info;

// Include Javascript
echo '<script src="' , $settings['default_theme_url'] , '/scripts/sorttable.js"></script>';

// First get all the NiceToolTip javascript in place if it's needed.
// The javascript is not needed when we are in a board as the NiceToolTip module
// will already have loaded it.  We just need to add it if we are elsewhere...

// So add the code if we are not in a board
// OR When viewing a topic the board is also set,
// so we need to add the javascript then too...

if (!isset($_GET['board']) || isset($_GET['topic']))
echo '
<style type="text/css">
.nice_tooltip_fgclass {
background-color: ' . $modSettings['NiceTooltips_FGCOLOR'] . ';
opacity: ' . $modSettings['NiceTooltips_OPACITY'] / 100 . ';
}
.nice_tooltip_bgclass {
background-color: ' . $modSettings['NiceTooltips_BGCOLOR'] . ';
opacity: ' . $modSettings['NiceTooltips_OPACITY'] / 100 . ';
}
</style>

<script language="JavaScript" type="text/javascript" src="' . $settings['default_theme_url'] . (!empty($modSettings['NiceTooltips_scripturl']) ? '/' . $modSettings['NiceTooltips_scripturl'] : '') . '/overlib_mini.js"></script>

<script language="JavaScript" type="text/javascript" src="' . $settings['default_theme_url'] . (!empty($modSettings['NiceTooltips_scripturl']) ? '/' . $modSettings['NiceTooltips_scripturl'] : '') . '/overlib_adaptive_width.js"></script>
';


// leave out the recycle board, if any
if(isset($modSettings['recycle_board']))
$exclude = array($modSettings['recycle_board']);
else
$exclude = array();
   
if ($exclude === null && !empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0)
$exclude = array($modSettings['recycle_board']);
else
$exclude = empty($exclude) ? array() : $exclude;

// Icons...
$stable_icons = array('xx', 'thumbup', 'thumbdown', 'exclamation', 'question', 'lamp', 'smiley', 'angry', 'cheesy', 'grin', 'sad', 'wink', 'moved', 'recycled', 'wireless', 'clip');
$icon_sources = array();
foreach ($stable_icons as $icon)
$icon_sources[$icon] = 'images_url';

// Are we looking for topics within a number of days ?
if ($num_days != 0)
$date_threshold = forum_time() - ($num_days * 24 * 60 * 60);

// Find all the posts in distinct topics.  Newer ones will have higher IDs.
// Stripped down and adapted from SSI.php ssi_recentTopics() function.

$request = tp_query("
SELECT
m.poster_time, ms.subject, m.id_topic, m.id_member, m.id_msg, b.id_board, b.name AS board_name, t.num_replies, t.num_views, t.is_sticky, t.locked, t.id_poll,
IFNULL(mem.real_name, m.poster_name) AS poster_name, " . ($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') . ",
LEFT(m.body, ". (!empty($modSettings['NiceTooltips_lenght']) ? $modSettings['NiceTooltips_lenght'] : 384) .") AS body, m.smileys_enabled, m.icon
FROM ({$db_prefix}messages AS m, {$db_prefix}topics AS t, {$db_prefix}boards AS b, {$db_prefix}messages AS ms)
LEFT JOIN {$db_prefix}members AS mem ON (mem.id_member = m.id_member)" . (!$user_info['is_guest'] ? "
LEFT JOIN {$db_prefix}log_topics AS lt ON (lt.id_topic = t.id_topic AND lt.id_member = {$context['user']['id']})
LEFT JOIN {$db_prefix}log_mark_read AS lmr ON (lmr.id_board = b.id_board AND lmr.id_member = {$context['user']['id']})" : '') . "
WHERE t.id_last_msg >= " . ($modSettings['maxMsgID'] - 35 * min($num_recent, 5)) . "
AND t.id_last_msg = m.id_msg
AND b.id_board = t.id_board" . (empty($exclude) ? '' : "
AND b.id_board NOT IN (" . implode(', ', $exclude) . ")") . "
AND $user_info[query_see_board]
AND ms.id_msg = t.id_first_msg"
. (($num_days != 0) ? "
AND m.poster_time > $date_threshold" : "") . "
ORDER BY t.id_last_msg DESC"
. (($num_days == 0) ? "
LIMIT $num_recent" : ""), __FILE__, __LINE__);


// An array to hold all the posts/new topics in.
$posts = array();

// use a counter for topics so we can track the index of the $posts array - if needed.
$topic_count = 0;

// Keeps track of topic ids found so we can see if the user posted in a topic - if needed.
$topic_ids = array();


while ($row = tpdb_fetch_assoc($request))
{
// Build the array.
$posts[] = array(
'board' => array(
'link' => '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['board_name'] . '</a>'
),
'topic' => $row['id_topic'],
'poster' => array(
'link' => empty($row['id_member']) ? $row['poster_name'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['poster_name'] . '</a>'
),
'subject' => $row['subject'],
'preview' => $row['body'],
'time' => timeformat($row['poster_time']),
'time_stamp' => $row['poster_time'],
'href' => $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . ';topicseen#new',
'link' => '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#new">' . $row['subject'] . '</a>',
'new' => !empty($row['is_read']),
'icon' => '<img src="' . $settings[$icon_sources[$row['icon']]] . '/post/' . $row['icon'] . '.gif" align="middle" alt="' . $row['icon'] . '" border="0" />',
'icon_type' => $row['icon'],
'views_replies' => $row['num_views'] . '/' . $row['num_replies'],
'is_sticky' => !empty($modSettings['enableStickyTopics']) && !empty($row['is_sticky']),
'is_locked' => !empty($row['locked']),
'is_poll' => $modSettings['pollMode'] == '1' && $row['id_poll'] > 0,
'is_hot' => $row['num_replies'] >= $modSettings['hotTopicPosts'],
'is_very_hot' => $row['num_replies'] >= $modSettings['hotTopicVeryPosts'],
);

// Are we showing the icon for class of topic ?  Otherwise ignore this part as it's not needed.
if ($show_class_icon == true)
{
// Use the SMF function that works out what icon class we need to show.
determineTopicClass($posts[$topic_count]);

// Add this topic to our array of topics being found.
$topic_ids[] = $row['id_topic'];

$topic_count++;
}
}

tpdb_free_result($request);

// Okay then, did that return any results ?
if (count($topic_ids) > 0)
{
// Again, are we showing the message/topic class icon ?  Otherwise don't bother with this bit.
if ($show_class_icon == true)
{
// See if the user posted in any of the topics found.
$request = tp_query("
SELECT id_topic
FROM {$db_prefix}messages
WHERE id_topic
IN (" . implode(', ',$topic_ids) . ")
AND id_member = {$context['user']['id']}
GROUP BY id_topic
LIMIT " . count($topic_ids), __FILE__, __LINE__);

// Now we know what topics the user posted in we can put them in an array
// and refer to it when we do the output so it shows the special 'my_' icons.
$posted_in = array();

while ($row = tpdb_fetch_assoc($request))
{
$posted_in[] = $row['id_topic'];
}
tpdb_free_result($request);
}


////////////////////////
// Now for the output...


// Set up the table and headings.
echo '
<table class="sortable" border="0" width="100%" cellspacing="1" cellpadding="3">
<tr class="titlebg" style="font-size:11px;cursor:hand;cursor:pointer">'
, ($show_class_icon ? '
<th></th>' : '')
, ($show_message_icon ? '
<th></th>' : '') , '
<th align="center">Subject</th>
<th align="center">Board</th>
<th align="center">Views/Replies</th>
<th align="center">Member</th>
<th align="center">Date & Time</th>
</tr>';

// Go through each topic.
foreach ($posts as $topic)
{
// Generate the popup.
$popup = NiceTooltip($topic['preview'], $topic['subject']);

echo '
<tr class="windowbg">';

 
if ($show_class_icon == true)
{
if (in_array($topic['topic'], $posted_in))
$topic['class'] = 'my_' . $topic['class'];

echo '
<td sorttable_customkey = "' , $topic['class'] , '" valign="middle">
<img src="' , $settings['images_url'] , '/topic/' , $topic['class'] , '.gif" alt="" />
</td>';
}

if ($show_message_icon == true)
echo '
<td sorttable_customkey = "' , $topic['icon_type'] , '" valign="middle">
' , $topic['icon'] , '
</td>';

echo '
<td>
<a href="' , $topic['href'] , '"' , $popup , '>' , $topic['subject'] , '</a>';

// Is this topic new? (assuming they are logged in!)
if (!$topic['new'] && $context['user']['is_logged'])
echo '
<a href="', $scripturl, '?topic=', $topic['topic'], '.from', $topic['time'], '#new"><img src="', $settings['images_url'], '/', $context['user']['language'], '/new.gif" alt="', $txt['new'], '" border="0" align="right", valign="absmiddle" /></a>';

echo '
</td>
<td valign="middle">' , $topic['board']['link'], '</td>';

echo '
<td valign="middle" align="center">' , $topic['views_replies'] , '</td>';

echo '
<td valign="middle" >', $topic['poster']['link'], '</td>
<td sorttable_customkey = "' , $topic['time_stamp'] , '" valign="middle" >';

if ($settings['images_url'] != $settings['theme_url'] . '/images' || file_exists($settings['theme_dir'] . '/images/icons/last_post.gif'))
echo '
<a href="', $topic['href'], '"><img src="', $settings['images_url'], '/icons/last_post.gif" alt="', $txt['last_post'], '" title="', $txt['last_post'], '" border="0" style="float: right;" /></a>';

echo '
<span class="smalltext">', $topic['time'], '</span>
</td>
</tr>';
}

echo '
</table>';

}
else // If there were no results do this...
{
if ($num_days)
{
echo '
<div style="text-align:center">
<em>There have been no posts in the past ' , $num_days , ' days...</em>
</div>';
}
else
{
echo '
<div style="text-align:center">
<em>There appears to be no posts in the forum !</em>
</div>';
}
}
« Last Edit: April 23, 2010, 12:42:06 PM by freddy888 »