TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

May 01, 2024, 12:09:58 AM

Login with username, password and session length
Members
  • Total Members: 3,885
  • Latest: Growner
Stats
  • Total Posts: 195,174
  • Total Topics: 21,220
  • Online today: 108
  • Online ever: 3,540 (September 03, 2022, 01:38:54 AM)
Users Online
  • Users: 0
  • Guests: 104
  • Total: 104

[Discussion] Recent topics table with hover over previews.

Started by alhaudhie, September 14, 2009, 04:58:20 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

lurkalot

Quote from: freddy888 on April 22, 2010, 06:35:06 PM
Yes well it should do lol

Tell me do you actually have any posts in your forum ?

Only about three, I got fed up with talking to myself.  :(

Freddy



Freddy

Hmmm... well Difficult for me to sort it from here....want to set me up an account with ability to use PHP articles ?  You can PM me if you like.

Freddy

#104
Actually I think I just figured it out.  If you left the settings as they were then it was looking for topics within the past 7 days.

And since your last post is more than 7 days ago it is not finding anything.

That's what is causing the problem with it not finding any topics.

Try changing :

$num_days = 7;

To :

$num_days = 30;

And I bet it starts working...

Edit : make it 30 I meant...sorry I put 3 originally.

lurkalot

 O0 worked like a dream, thanks Freddy.

Only thing that concerns me is when there's no posts to show it stops my right panels from working, and throws the error. 

Is this a bug?  Not that it would show up on an active forum I suppose.

Freddy

Yeah, I consider it a bug really.  I'm just recoding it a little to pick up on that.

So that if there are no results it says something like :

"There are no topics from the past 7 days..."

Better to be safe than sorry.  Thanks for the bug hunting :)

lurkalot

Quote from: freddy888 on April 22, 2010, 07:28:49 PM

Better to be safe than sorry.  Thanks for the bug hunting :)


No problem, thanks for helping me with this.  ;)


Freddy

Here's a new version with the 'no results' bug fixed.


// *********************************************************************
// 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!!
// !!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 : 21 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>';
}
}

lurkalot

Thanks, tested and working for me. ;)

There have been no posts in the past 7 days...   O0