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

Recent

Welcome to TinyPortal. Please login or sign up.

Members
  • Total Members: 3,963
  • Latest: BiZaJe
Stats
  • Total Posts: 195,915
  • Total Topics: 21,308
  • Online today: 884
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online

custom "Recent Topics from Board X, Y, Z only" php block

Started by iowamf, November 04, 2005, 09:47:16 AM

Previous topic - Next topic

0 Members and 2 Guests are viewing this topic.

Freddy

You need to add the extra code into SSI.php, by which I mean the ssi_recentTopics_Include() function that is somewhere back in this thread.  Just read through the thread and it's there somewhere.

Jags

Hi Freddy,

Thanks a lot for your reply.. I modified the SSI.php file and it is working fine.. I just need a bit more help.

I want this block to look similar to the default block of recent topics as in Tinyportal.
As is given in the right hand side of this forum..
http://just4dosti.com/forum/

The recent block given on left of this site (http://www.tinyportal.co.uk) is also similar to what I need.

Freddy

No problem.

If you are happy with the content then can you post the code you are using and I will change the layout.

If you could also post the  ssi_recentTopics_Include() function too that would be helpful.

Remember to put each bit of code in code (# button in editor) tags.

Jags

Wow.. It was prompt....  :)

Here's the code I'm using....

Block Code
global $context, $scripturl, $settings, $txt;

//define the two images for read/unread replies
$bullet = '<img src="'.$settings['images_url'].'/TPdivider5.gif" alt="" border="0" style="margin:0 2px 0 0;" />';
$bullet2 = '<img src="'.$settings['images_url'].'/TPdivider4.gif" alt="" border="0" style="margin:0 2px 0 0;" />';

$result=ssi_recentTopics_Include(4,array(19, 8),'return');
// show the board name
echo '<span class="smalltext"><b><a href="http://www.just4dosti.com/index.php?board=19.0">Newsposters</a>:</b><br /></span>';
// and now, the latests posts
foreach($result as $my){
  echo "$bullet";
  echo '<span class="smalltext">' , $my['link'] , ' (' , $my['numReplies'] , ') ' , $my['poster']['link'];

  // is this topic new? (assume they are logged in)
if (!$my['new'] && $context['user']['is_logged'])
        echo ' <a href="http://just4dosti.com/', $scripturl, '?topic=', $my['topic'], '.from', $my['new_from'], '#new"></a>';
echo '<br />';

echo '</span>';

}


SSI_RecentTopics_Include function

function ssi_recentTopics_Include($num_recent = 8, $include_boards = null, $output_method = 'echo')
{
global $context, $settings, $scripturl, $txt, $db_prefix, $ID_MEMBER;
global $user_info, $modSettings, $func;

$include_boards = empty($include_boards) ? array() : $include_boards;

$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 all the posts in distinct topics.  Newer ones will have higher IDs.
$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, 384) AS body, m.smileysEnabled, 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 = $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($include_boards) ? '' : "
                  AND b.ID_BOARD IN (" . implode(', ', $include_boards) . ")") . "
                  " . ((!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0) ? "
                  AND b.ID_BOARD != '$modSettings[recycle_board]'" : '') . "
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))
{
$row['body'] = strip_tags(strtr(parse_bbc($row['body'], $row['smileysEnabled'], $row['ID_MSG']), array('<br />' => '')));
if ($func['strlen']($row['body']) > 128)
$row['body'] = $func['substr']($row['body'], 0, 128) . '...';

// Censor the subject.
censorText($row['subject']);
censorText($row['body']);

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';

// 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'] . '#new">' . $row['subject'] . '</a>',
'new' => !empty($row['isRead']),
'new_from' => $row['new_from'],
'icon' => '<img src="' . $settings[$icon_sources[$row['icon']]] . '/post/' . $row['icon'] . '.gif" align="middle" alt="' . $row['icon'] . '" border="0" />',
);
}
mysql_free_result($request);

// Just return it.
if ($output_method != 'echo' || empty($posts))
return $posts;

echo '
<table border="0" class="ssi_table">';
foreach ($posts as $post)
echo '
<tr>
<td align="right" valign="top" nowrap="nowrap">
[', $post['board']['link'], ']
</td>
<td valign="top">
<a href="', $post['href'], '">', $post['subject'], '</a>
', $txt[525], ' ', $post['poster']['link'], '
', $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[302] . '" border="0" /></a>', '
</td>
<td align="right" nowrap="nowrap">
', $post['time'], '
</td>
</tr>';
echo '
</table>';
}

Freddy

#164
Thanks, that helps a lot  O0

Try this block code out, it should look exactly like the layout you are using on your site :

global $context, $scripturl;

// limit, boards, method
$result=ssi_recentTopics_Include(4,array(19, 8),'return');

// show the board name
echo '
<span class="smalltext">
<b><a href="http://www.just4dosti.com/index.php?board=19.0">Newsposters</a>:</b><br />
</span>';

// and now, the latests posts

echo '
<ul class="tp_recentblock">';

foreach($result as $my)
{
echo '
<li style="overflow: auto">';

if (strlen($my['subject']) > 25)
{
echo '
<a href="' , $my['href'] , '">' , substr($my['subject'], 0, 24) . '...</a>';
}
else
{
echo $my['link'];
}

echo ' by ' , $my['poster']['link'] , ' [' , $my['time'] , ']';

// is this topic new? (assume they are logged in)
if (!$my['new'] && $context['user']['is_logged'])
echo ' <a href="http://just4dosti.com/', $scripturl, '?topic=', $my['topic'], '.from', $my['new_from'], '#new"></a>';

echo '
</li>';
}

echo '
</ul>';



I am not sure about this line near the end :

// is this topic new? (assume they are logged in)
if (!$my['new'] && $context['user']['is_logged'])
echo ' <a href="http://just4dosti.com/', $scripturl, '?topic=', $my['topic'], '.from', $my['new_from'], '#new"></a>';


It doesn't really do anything, it makes a link, but not a link you can click.  I left it in, just in case it is something you are working on.

Jags

Freddy,

I think I messed up something, I just copied the code and used inside a new PHP block, I'm getting the following error..

Parse error: syntax error, unexpected ',' in /home/just4dos/public_html/Sources/Load.php(1806) : eval()'d code(48) : eval()'d code on line 4

I tried to figure it out, but my limited knowledge of PHP didn't work.. :)

The screenshot you posted is exactly what I need.

Quote from: Freddy on September 24, 2010, 01:23:46 PM

I am not sure about this line near the end :

// is this topic new? (assume they are logged in)
if (!$my['new'] && $context['user']['is_logged'])
echo ' <a href="http://just4dosti.com/', $scripturl, '?topic=', $my['topic'], '.from', $my['new_from'], '#new"></a>';


It doesn't really do anything, it makes a link, but not a link you can click.  I left it in, just in case it is something you are working on.
I had just copied the code from a post in this thread, I myself is not sure what the above code does....  :uglystupid2:

Sorry for my bad English and a late reply, I couldn't come online this weekend.. :)

Freddy

No problem.  It wasn't you, it was me.  When I changed the categories back to using your ones I inadvertently added in an extra ) bracket.

I edited the code above to remove it so try again now.

Sorry about that   :idiot2:

About that extra line, well to me it looks like it might be meant to show the 'new' icon for when a post is unread, except the code is incomplete.  Do you want that feature or are you not fussed ?

Your English is fine, I thought it was your first language  8)

Jags

Thanku soooooooo much Freddy.... It worked like a charm. I don't need the 'new' feature as of now....

Thanks for all the help provided..  :)


The Wizard

Link to my site: http://www.tribeuniverse.com
SMF version: 2.0 RC4
TP version: 1.0 RC1
Default Forum Language: English
Theme name and version:CurveLife
Browser Name and Version: IE
Mods installed:Tiny Portal, Aeva Media
Related Error messages: None

Hello:

I have been reading thought this thread and I trully dont know where to start on this I have tryed a few of the codes, but I don't think they work with the  version I have.

What I would like to do is list all the topics in a parent board of my choice. I want the topics to be links. I don't care about who wrote the topic, when it was posted ect.. I just want the name of the topic and make it a link. I would like the topics in alphabectical order, but I'm not married to the idea. So if anybody can give me the code and the steps to pull this off it would be helpfull.
Thanks

This website is proudly hosted on Crocweb Cloud Website Hosting.