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,917
  • Total Topics: 21,308
  • Online today: 884
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 0
  • Guests: 408
  • Total: 408

[Block] Number of replies at recent topics block

Started by johnkal, June 08, 2009, 08:19:04 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

johnkal

Hi,

how can i make to show the number of replies at every topic?

I have attach a pic for example  :)

I find at TPortalBlocks.template.php this code but dont know how to make it ..


// TPortal recent topics block
function TPortal_recentbox()
{
global $context, $settings, $options, $txt , $modSettings;

    // is it a number?
if(!is_numeric($context['TPortal']['recentboxnum']))
$context['TPortal']['recentboxnum']='10';

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

$what=ssi_recentTopics($num_recent = $context['TPortal']['recentboxnum'], $bb, $output_method = 'array');
// Output the topics
$counter=1; $cmax=count($what);
echo '
<div style="width: 100%; ' , $context['TPortal']['recentboxscroll']==1 ? 'overflow: auto; height: 20ex;' : '' , '">';
foreach($what as $w){
echo '
<div class="smalltext"><a href="'.$w['href'].'">'.$w['short_subject'].'</a></div>
<div class="smalltext">', $txt[525], ' <b>', $w['poster']['link'], '</b></div>
<div class="smalltext">';
if(!$w['new'])
echo '<a href="'.$w['href'].'"><img border="0" src="'.$settings['images_url'].'/'.$context['user']['language'].'/new.gif" alt="new" /></a> ';

echo '['.$w['time'].']
</div>';

if($counter != $cmax)
echo '<hr />';
$counter++;
}
echo '

</div>';
}


thanks!!  :)

JPDeni

#1
Put this in a php block:


global $context, $settings, $scripturl, $txt, $db_prefix, $ID_MEMBER;
global $user_info, $modSettings, $func;
$num_recent = 8;
$exclude_boards = null;
$output_method = 'echo';
if ($exclude_boards === null && !empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0)
$exclude_boards = array($modSettings['recycle_board']);
else
$exclude_boards = empty($exclude_boards) ? array() : $exclude_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, t.numReplies,
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($exclude_boards) ? '' : "
AND b.ID_BOARD NOT IN (" . implode(', ', $exclude_boards) . ")") . "
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(
'topic' => $row['ID_TOPIC'],
'poster' => empty($row['ID_MEMBER']) ? $row['posterName'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] . '">' . $row['posterName'] . '</a>',
'short_subject' => shorten_subject($row['subject'], 25),
'time' => timeformat($row['posterTime']),
'href' => $scripturl . '?topic=' . $row['ID_TOPIC'] . '.msg' . $row['ID_MSG'] . ';topicseen#new',
'new' => !empty($row['isRead']),
'new_from' => $row['new_from'],
'replies' => $row['numReplies'],
);
}
mysql_free_result($request);

// Just return it.
$counter=1; $cmax=count($posts);
echo '
<div style="width: 100%;>';
foreach ($posts as $post)
{
echo '
<div class="smalltext"><a href="'.$post['href'].'">'.$post['short_subject'].'</a> (' . $post['replies'] . ')</div>
<div class="smalltext">', $txt[525], ' <b>', $post['poster'], '</b></div>
<div class="smalltext">';
if(!$post['new'])
echo '<a href="'.$post['href'].'"><img border="0" src="'.$settings['images_url'].'/'.$context['user']['language'].'/new.gif" alt="new" /></a> ';

echo '[' . $post['time'] . ']
</div>';

if($counter != $cmax)
echo '<hr />';
$counter++;
}
echo '
</div>';

johnkal

Thanks for your answer :)

Quote from: JPDeni on June 08, 2009, 12:48:32 PM
Since the number of replies isn't part of the ssi_recentTopics function, you'll need to use a copy of that function with the added feature.

How?

i have try your code and i take this error..

QuoteParse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ')' in /home/xxxxx/public_html/Sources/Load.php(1777) : eval()'d code(35) : eval()'d code on line 53"

JPDeni

Quote
How?

By using the code I gave you.

I fixed the error. I'd left out a comma. :)

johnkal

With the new code the index.php don't load..!
I think it can't connect with the database to take the results of replies!


johnkal


JPDeni

You're welcome. :) I'm not sure what the problem was, really. I redid the whole code and it finally worked right. I guess I got the magic right the second time. :)

Herr Inoddorell

The Code works excellent JP, but I would like that the "new.gif" were right after the replies count number. I tried to modify the code, but can't get it to work. Could someone help me with this, please?

This is the code I'm using:


global $context, $settings, $scripturl, $txt, $db_prefix, $ID_MEMBER;
global $user_info, $modSettings, $func;
$num_recent = 8;
$exclude_boards = null;
$output_method = 'echo';
if ($exclude_boards === null && !empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0)
$exclude_boards = array($modSettings['recycle_board']);
else
$exclude_boards = empty($exclude_boards) ? array() : $exclude_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, t.numReplies,
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($exclude_boards) ? '' : "
AND b.ID_BOARD NOT IN (" . implode(', ', $exclude_boards) . ")") . "
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(
'topic' => $row['ID_TOPIC'],
'poster' => empty($row['ID_MEMBER']) ? $row['posterName'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] . '">' . $row['posterName'] . '</a>',
'short_subject' => shorten_subject($row['subject'], 25),
'time' => timeformat($row['posterTime']),
'href' => $scripturl . '?topic=' . $row['ID_TOPIC'] . '.msg' . $row['ID_MSG'] . ';topicseen#new',
'new' => !empty($row['isRead']),
'new_from' => $row['new_from'],
'replies' => $row['numReplies'],
);
}
mysql_free_result($request);

// Just return it.
$counter=1; $cmax=count($posts);
echo '
<div style="width: 100%; ' , $context['TPortal']['recentboxscroll']==1 ? 'overflow: auto; height: 20ex;' : '' , '">';
foreach ($posts as $post)
{
echo '
<div class="normal"><a href="'.$post['href'].'">'.$post['short_subject'].'</a></div>
                        <div class="smalltext">(' . $post['replies'] . ' Respuestas)</div>
<div class="smalltext">', $txt[525], ' <b>', $post['poster'], '</b></div>
<div class="smalltext">';
if(!$post['new'])
echo '<a href="'.$post['href'].'"><img border="0" src="'.$settings['images_url'].'/'.$context['user']['language'].'/new.gif" alt="new" /></a> ';

echo '[' . $post['time'] . ']
</div>';

if($counter != $cmax)
echo '<hr />';
$counter++;
}
echo '
</div>';


Thanks in advance! ;)

JPDeni

This should work.

Replace


<div class="normal"><a href="'.$post['href'].'">'.$post['short_subject'].'</a></div>
                        <div class="smalltext">(' . $post['replies'] . ' Respuestas)</div>
<div class="smalltext">', $txt[525], ' <b>', $post['poster'], '</b></div>
<div class="smalltext">';
if(!$post['new'])
echo '<a href="'.$post['href'].'"><img border="0" src="'.$settings['images_url'].'/'.$context['user']['language'].'/new.gif" alt="new" /></a> ';

echo '[' . $post['time'] . ']
</div>';


with



<div class="normal"><a href="'.$post['href'].'">'.$post['short_subject'].'</a></div>
                        <div class="smalltext">(' . $post['replies'] . ' Respuestas)';
if(!$post['new'])
echo '<a href="'.$post['href'].'"><img border="0" src="'.$settings['images_url'].'/'.$context['user']['language'].'/new.gif" alt="new" /></a> ';
echo '
</div>
<div class="smalltext">', $txt[525], ' <b>', $post['poster'], '</b></div>
<div class="smalltext">';

echo '[' . $post['time'] . ']
</div>';

This website is proudly hosted on Crocweb Cloud Website Hosting.