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

Recent

Welcome to TinyPortal. Please login or sign up.

Members
Stats
  • Total Posts: 196,023
  • Total Topics: 21,333
  • Online today: 899
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 1
  • Guests: 726
  • Total: 727
  • lurkalot

Top 10 topics

Started by EG, August 10, 2006, 10:37:59 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

EG

Ive had a request from my members to include these as a block...

Ive looked at the stats.template.php  and figure I need this block of php code

<table>
<td class="catbg" colspan="2" width="50%"><b>', $txt['smf_stats_11'], '</b></td>
<td class="catbg" colspan="2" width="50%"><b>', $txt['smf_stats_12'], '</b></td>
</tr><tr>
<td class="windowbg" width="20" valign="middle" align="center"><img src="', $settings['images_url'], '/stats_replies.gif" width="20" height="20" alt="" /></td>
<td class="windowbg2" width="50%" valign="top">
<table border="0" cellpadding="1" cellspacing="0" width="100%">';
foreach ($context['top_topics_replies'] as $topic)
echo '
<tr>
<td width="60%" valign="top">', $topic['link'], '</td>
<td width="20%" align="left" valign="top">', $topic['num_replies'] > 0 ? '<img src="' . $settings['images_url'] . '/bar.gif" width="' . $topic['post_percent'] . '" height="15" alt="" />' : ' ', '</td>
<td width="20%" align="right" valign="top">', $topic['num_replies'], '</td>
</tr></table>


I used a phpblock, and put it in, but am now getting a parse error

QuoteParse error: parse error, unexpected '<' in /lotruk/forum/Sources/Load.php(1606) : eval()'d code(34) : eval()'d code on line 2


so figure, something somewhere is missing :-\ 

Could anyone point me in the right direction ?  thanks :)

jacortina

Is the above all you have in the phpblock?

Do you have a 'globals' line to pull in the arrays/variables?

is the above within an 'echo' statement?

EG

thanks!

Ive checked and added the globals line... so now the code says this... there are no errors... but no statistics either ;)

global $context, $settings, $options, $txt, $scripturl, $modSettings;

echo '<b>', $txt['smf_stats_11'], '</b>
<br><b>', $txt['smf_stats_12'], '</b><img src="', $settings['images_url'], '/stats_replies.gif" width="20" height="20" alt="" <br> ';
foreach ($context['top_topics_replies'] as $topic)
echo '
', $topic['link'], ' ', $topic['num_replies'] > 0 ? '<img src="' . $settings['images_url'] . '/bar.gif" width="' . $topic['post_percent'] . '" height="15" alt="" />' : ' ', '
', $topic['num_replies'], '
';

jacortina

Ah, $context array won't get loaded with that information unless you copy the relevant
code from Stats.php and run it beforehand (add $db_prefix and $user_info to globals line
and insert this below globals and before your first echo):


// Are you on a larger forum?  If so, let's try to limit the number of topics we search through.
if ($modSettings['totalMessages'] > 100000)
{
$request = db_query("
SELECT ID_TOPIC
FROM {$db_prefix}topics
WHERE numReplies != 0
ORDER BY numReplies DESC
LIMIT 100", __FILE__, __LINE__);
$topic_ids = array();
while ($row = mysql_fetch_assoc($request))
$topic_ids[] = $row['ID_TOPIC'];
mysql_free_result($request);
}
else
$topic_ids = array();

// Topic replies top 10.
$topic_reply_result = db_query("
SELECT m.subject, t.numReplies, t.ID_BOARD, t.ID_TOPIC, b.name
FROM ({$db_prefix}topics AS t, {$db_prefix}messages AS m, {$db_prefix}boards AS b)
WHERE m.ID_MSG = t.ID_FIRST_MSG
AND $user_info[query_see_board]" . (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? "
AND b.ID_BOARD != $modSettings[recycle_board]" : '') . "
AND t.ID_BOARD = b.ID_BOARD" . (!empty($topic_ids) ? "
AND t.ID_TOPIC IN (" . implode(', ', $topic_ids) . ")" : '') . "
ORDER BY t.numReplies DESC
LIMIT 10", __FILE__, __LINE__);
$context['top_topics_replies'] = array();
$max_num_replies = 1;
while ($row_topic_reply = mysql_fetch_assoc($topic_reply_result))
{
censorText($row_topic_reply['subject']);

$context['top_topics_replies'][] = array(
'id' => $row_topic_reply['ID_TOPIC'],
'board' => array(
'id' => $row_topic_reply['ID_BOARD'],
'name' => $row_topic_reply['name'],
'href' => $scripturl . '?board=' . $row_topic_reply['ID_BOARD'] . '.0',
'link' => '<a href="' . $scripturl . '?board=' . $row_topic_reply['ID_BOARD'] . '.0">' . $row_topic_reply['name'] . '</a>'
),
'subject' => $row_topic_reply['subject'],
'num_replies' => $row_topic_reply['numReplies'],
'href' => $scripturl . '?topic=' . $row_topic_reply['ID_TOPIC'] . '.0',
'link' => '<a href="' . $scripturl . '?topic=' . $row_topic_reply['ID_TOPIC'] . '.0">' . $row_topic_reply['subject'] . '</a>'
);

if ($max_num_replies < $row_topic_reply['numReplies'])
$max_num_replies = $row_topic_reply['numReplies'];
}
mysql_free_result($topic_reply_result);

foreach ($context['top_topics_replies'] as $i => $topic)
$context['top_topics_replies'][$i]['post_percent'] = round(($topic['num_replies'] * 100) / $max_num_replies);

jacortina

BTW, do you know there's an ssi function that does basically the same thing?

EG

is there ?  ive never really got the hang of ssi functions :(

EG

OH WOW!  youre a star!!!

dammit, should have thought about checking stats.php too ::)  I just assumed that because the forum was running that, it would pick it up anyway :-\

Quote from: jacortina on August 10, 2006, 04:25:34 PM
Ah, $context array won't get loaded with that information unless you copy the relevant
code from Stats.php and run it beforehand (add $db_prefix and $user_info to globals line
and insert this below globals and before your first echo):


// Are you on a larger forum?  If so, let's try to limit the number of topics we search through.
if ($modSettings['totalMessages'] > 100000)
{
$request = db_query("
SELECT ID_TOPIC
FROM {$db_prefix}topics
WHERE numReplies != 0
ORDER BY numReplies DESC
LIMIT 100", __FILE__, __LINE__);
$topic_ids = array();
while ($row = mysql_fetch_assoc($request))
$topic_ids[] = $row['ID_TOPIC'];
mysql_free_result($request);
}
else
$topic_ids = array();

// Topic replies top 10.
$topic_reply_result = db_query("
SELECT m.subject, t.numReplies, t.ID_BOARD, t.ID_TOPIC, b.name
FROM ({$db_prefix}topics AS t, {$db_prefix}messages AS m, {$db_prefix}boards AS b)
WHERE m.ID_MSG = t.ID_FIRST_MSG
AND $user_info[query_see_board]" . (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? "
AND b.ID_BOARD != $modSettings[recycle_board]" : '') . "
AND t.ID_BOARD = b.ID_BOARD" . (!empty($topic_ids) ? "
AND t.ID_TOPIC IN (" . implode(', ', $topic_ids) . ")" : '') . "
ORDER BY t.numReplies DESC
LIMIT 10", __FILE__, __LINE__);
$context['top_topics_replies'] = array();
$max_num_replies = 1;
while ($row_topic_reply = mysql_fetch_assoc($topic_reply_result))
{
censorText($row_topic_reply['subject']);

$context['top_topics_replies'][] = array(
'id' => $row_topic_reply['ID_TOPIC'],
'board' => array(
'id' => $row_topic_reply['ID_BOARD'],
'name' => $row_topic_reply['name'],
'href' => $scripturl . '?board=' . $row_topic_reply['ID_BOARD'] . '.0',
'link' => '<a href="' . $scripturl . '?board=' . $row_topic_reply['ID_BOARD'] . '.0">' . $row_topic_reply['name'] . '</a>'
),
'subject' => $row_topic_reply['subject'],
'num_replies' => $row_topic_reply['numReplies'],
'href' => $scripturl . '?topic=' . $row_topic_reply['ID_TOPIC'] . '.0',
'link' => '<a href="' . $scripturl . '?topic=' . $row_topic_reply['ID_TOPIC'] . '.0">' . $row_topic_reply['subject'] . '</a>'
);

if ($max_num_replies < $row_topic_reply['numReplies'])
$max_num_replies = $row_topic_reply['numReplies'];
}
mysql_free_result($topic_reply_result);

foreach ($context['top_topics_replies'] as $i => $topic)
$context['top_topics_replies'][$i]['post_percent'] = round(($topic['num_replies'] * 100) / $max_num_replies);


Max


I will move this to Block code snippets.

EG

#8
In which case, have the code in its entirety ....Ã,  Ive removed from the stats section the number of replies and the status bar ...... so it just now shows the topics (linked) with a <hr> between each


global $context, $settings, $options, $txt, $scripturl, $modSettings, $db_prefix, $user_info ;

// Are you on a larger forum?Ã,  If so, let's try to limit the number of topics we search through.
if ($modSettings['totalMessages'] > 100000)
{
$request = db_query("
SELECT ID_TOPIC
FROM {$db_prefix}topics
WHERE numReplies != 0
ORDER BY numReplies DESC
LIMIT 100", __FILE__, __LINE__);
$topic_ids = array();
while ($row = mysql_fetch_assoc($request))
$topic_ids[] = $row['ID_TOPIC'];
mysql_free_result($request);
}
else
$topic_ids = array();

// Topic replies top 10.
$topic_reply_result = db_query("
SELECT m.subject, t.numReplies, t.ID_BOARD, t.ID_TOPIC, b.name
FROM ({$db_prefix}topics AS t, {$db_prefix}messages AS m, {$db_prefix}boards AS b)
WHERE m.ID_MSG = t.ID_FIRST_MSG
AND $user_info[query_see_board]" . (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? "
AND b.ID_BOARD != $modSettings[recycle_board]" : '') . "
AND t.ID_BOARD = b.ID_BOARD" . (!empty($topic_ids) ? "
AND t.ID_TOPIC IN (" . implode(', ', $topic_ids) . ")" : '') . "
ORDER BY t.numReplies DESC
LIMIT 10", __FILE__, __LINE__);
$context['top_topics_replies'] = array();
$max_num_replies = 1;
while ($row_topic_reply = mysql_fetch_assoc($topic_reply_result))
{
censorText($row_topic_reply['subject']);

$context['top_topics_replies'][] = array(
'id' => $row_topic_reply['ID_TOPIC'],
'board' => array(
'id' => $row_topic_reply['ID_BOARD'],
'name' => $row_topic_reply['name'],
'href' => $scripturl . '?board=' . $row_topic_reply['ID_BOARD'] . '.0',
'link' => '<a href="' . $scripturl . '?board=' . $row_topic_reply['ID_BOARD'] . '.0">' . $row_topic_reply['name'] . '</a>'
),
'subject' => $row_topic_reply['subject'],
'num_replies' => $row_topic_reply['numReplies'],
'href' => $scripturl . '?topic=' . $row_topic_reply['ID_TOPIC'] . '.0',
'link' => '<a href="' . $scripturl . '?topic=' . $row_topic_reply['ID_TOPIC'] . '.0">' . $row_topic_reply['subject'] . '</a>'
);

if ($max_num_replies < $row_topic_reply['numReplies'])
$max_num_replies = $row_topic_reply['numReplies'];
}
mysql_free_result($topic_reply_result);

foreach ($context['top_topics_replies'] as $i => $topic)
$context['top_topics_replies'][$i]['post_percent'] = round(($topic['num_replies'] * 100) / $max_num_replies);


echo '<b>', $txt['smf_stats_11'], '</b>
<br><b>', $txt['smf_stats_12'], '</b> ';
foreach ($context['top_topics_replies'] as $topic)
echo ' <div class="smalltext">
', $topic['link'], ' </div><hr> ', $topic['num_replies'] > 0 ? '' : ' ', '
', '
';



This website is proudly hosted on Crocweb Cloud Website Hosting.