Login  |  Register
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome, Guest. Please login or register.
Did you miss your activation email?

August 10, 2022, 08:20:04 PM

Login with username, password and session length
Members
  • Total Members: 3842
  • Latest: Kokoro
Stats
  • Total Posts: 193479
  • Total Topics: 21088
  • Online today: 53
  • Online ever: 1035
  • (November 26, 2020, 04:45:12 AM)
Users Online
Users: 0
Guests: 45
Total: 45

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

0 Members and 1 Guest are viewing this topic.

Offline Freddy

  • Moderator
  • *
  • Posts: 1615
    • AiDreams
[Block] Recent POSTS table with hover over previews.
« on: January 02, 2010, 01:20:51 PM »
Name of Snippet: Recent POSTS table with hover over previews
SMF/TP versions tested: SMF 1.1.11; TinyPortal v1.0 beta 4
Block Type: PHP
Author: freddy888, mrcare and digger at SMF
Link to Discussion: n/a
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 posts as you decide in a formatted table - note that it will show replies to posts as well as the original.

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: January 03, 2010, 01:45:00 AM by freddy888 »

Offline Freddy

  • Moderator
  • *
  • Posts: 1615
    • AiDreams
Re: [Block] Recent POSTS table with hover over previews.
« Reply #1 on: January 02, 2010, 01:36:44 PM »
Code: [Select]
// *********************************************************************
// A PHP block by Freddy888 and MrCare
// Used alongside the NiceToolTips mod, will show
// recent posts 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=31630

// Tested on : SMF 1.1.11; TinyPortal v1.0 beta 4
// This version : 2 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();


$ex_aeva = empty($modSettings['aeva_enable']) ? 0 : 1;
$modSettings['aeva_enable'] = 0;
   
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.  Newer ones will have higher IDs.
// Taken from SSI.php

$request = db_query("
SELECT
m.posterTime, m.subject, m.ID_TOPIC, m.ID_MEMBER, m.ID_MSG, m.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}boards AS b)
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 = m.ID_TOPIC AND lt.ID_MEMBER = $ID_MEMBER)
LEFT JOIN {$db_prefix}log_mark_read AS lmr ON (lmr.ID_BOARD = m.ID_BOARD AND lmr.ID_MEMBER = $ID_MEMBER)" : '') . "
WHERE m.ID_MSG >= " . ($modSettings['maxMsgID'] - 25 * min($num_recent, 5)) . "
AND b.ID_BOARD = m.ID_BOARD" . (empty($exclude) ? '' : "
AND b.ID_BOARD NOT IN (" . implode(', ', $exclude) . ")") . "
AND $user_info[query_see_board]
ORDER BY m.ID_MSG DESC
LIMIT $num_recent", __FILE__, __LINE__);

$posts = array();

while ($row = mysql_fetch_assoc($request))
{
// Build the array.
$posts[] = array(
'board' => array(
'id' => $row['ID_BOARD'],
'name' => $row['bName'],
'href' => $scripturl . '?board=' . $row['ID_BOARD'] . '.0',
'link' => '<a href="' . $scripturl . '?board=' . $row['ID_BOARD'] . '.0">' . $row['bName'] . '</a>'
),
'topic' => $row['ID_TOPIC'],
'poster' => array(
'id' => $row['ID_MEMBER'],
'name' => $row['posterName'],
'href' => empty($row['ID_MEMBER']) ? '' : $scripturl . '?action=profile;u=' . $row['ID_MEMBER'],
'link' => empty($row['ID_MEMBER']) ? $row['posterName'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] . '">' . $row['posterName'] . '</a>'
),
'subject' => $row['subject'],
'short_subject' => shorten_subject($row['subject'], 25),
'preview' => $row['body'],
'time' => timeformat($row['posterTime']),
'timestamp' => forum_time(true, $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'] . '#msg' . $row['ID_MSG'] . '">' . $row['subject'] . '</a>',
'new' => !empty($row['isRead']),
'new_from' => $row['new_from'],
);
}
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">
<span class="smalltext">', $topic['time'], '</span>
</td>
</tr>';
}

echo '
</table>';
« Last Edit: January 03, 2010, 12:25:20 AM by freddy888 »