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

Recent

Welcome to TinyPortal. Please login or sign up.

May 18, 2024, 01:25:47 PM

Login with username, password and session length
Members
  • Total Members: 3,886
  • Latest: Grendor
Stats
  • Total Posts: 195,189
  • Total Topics: 21,220
  • Online today: 112
  • Online ever: 3,540 (September 03, 2022, 01:38:54 AM)
Users Online
  • Users: 0
  • Guests: 46
  • Total: 46

Karma Leaders Block

Started by Xarcell, October 25, 2005, 03:48:23 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Nokonium

I've been fiddling for the last couple of hours trying to do a Karma Totals block based on the SMF code from Tau Online and now I'm stuck.

I have this added to Stats.php
// Top 5 Karma Rating
$karma_results = db_query("
SELECT realName, karmaGood, ID_MEMBER FROM {$db_prefix}members ORDER BY karmaGood DESC LIMIT 5", __FILE__, __LINE__);

$context['karma'] = array();

while( $row_karma = mysql_fetch_assoc($karma_results) )
{
$context['gkarma'][] = array(
'Karma' => $row_karma['karmaGood'],
'Link' => '<a href="' . $scripturl . '?action=profile;u=' . $row_karma['ID_MEMBER'] . '">' . $row_karma['realName'] . '</a>'
);
}

// Bottom 5 Karma Rating
$karma_results = db_query("
SELECT realName, karmaBad, ID_MEMBER FROM {$db_prefix}members ORDER BY karmaBad DESC LIMIT 5", __FILE__, __LINE__);

$context['bkarma'] = array();

while( $row_karma = mysql_fetch_assoc($karma_results) )
{
$context['bkarma'][] = array(
'Link' => '<a href="' . $scripturl . '?action=profile;u=' . $row_karma['ID_MEMBER'] . '">' . $row_karma['realName'] . '</a>',
'Karma' => $row_karma['karmaBad']
);
}

// Highest Total Karma
$karma_results = db_query("
SELECT karmaGood, karmaBad, realName, ID_MEMBER FROM {$db_prefix}members ORDER BY (karmaGood-karmaBad) DESC LIMIT 5", __FILE__, __LINE__);

$context['htkarma'] = array();

while( $row_karma = mysql_fetch_assoc($karma_results) )
{
$context['htkarma'][] = array(
'Link' => '<a href="' . $scripturl . '?action=profile;u=' . $row_karma['ID_MEMBER'] . '">' . $row_karma['realName'] . '</a>',
'Good' => $row_karma['karmaGood'],
'Bad' => $row_karma['karmaBad']
);
}

// Lowest karma total
$karma_results = db_query("
SELECT karmaGood, karmaBad, realName, ID_MEMBER FROM {$db_prefix}members ORDER BY (karmaGood-karmaBad) ASC LIMIT 5", __FILE__, __LINE__);

$context['ltkarma'] = array();

while( $row_karma = mysql_fetch_assoc($karma_results) )
{
$context['ltkarma'][] = array(
'Link' => '<a href="' . $scripturl . '?action=profile;u=' . $row_karma['ID_MEMBER'] . '">' . $row_karma['realName'] . '</a>',
'Good' => $row_karma['karmaGood'],
'Bad' => $row_karma['karmaBad']
);
}


And when this is added to Stats.template.php
if( $modSettings['karmaMode'] == 1 )
{
echo '<tr>
<td class="catbg" colspan="2">Well Bogled</td>
<td class="catbg" colspan="2">Goody Two Shoes</td>
</tr>
<tr>
<td class="windowbg" colspan="1">
<img src="'. $settings['images_url']. '/stats_posters.gif" width="20" height="20" />
</td>
<td class="windowbg2">';

foreach($context['htkarma'] as $htkarma)
{
$total = $htkarma['Good'] - $htkarma['Bad'];
echo '<table border="0" cellpadding="1" cellspacing="0" width="100%"><tr>
<td class="windowbg2" width="80%" align="left">'.
$htkarma['Link']
.'</td>
<td class="windowbg2" width="20%" align="right">'.$total.'</td>
</tr></table>';
}

echo'</td><td class="windowbg" colspan="1">
<img src="'. $settings['images_url']. '/stats_posters.gif" width="20" height="20" />
</td>
<td class="windowbg2">';


foreach($context['ltkarma'] as $ltkarma)
{
$total = $ltkarma['Good'] - $ltkarma['Bad'];
echo '<table border="0" cellpadding="1" cellspacing="0" width="100%"><tr>
<td class="windowbg2" width="80%" align="left">'.
$ltkarma['Link']
.'</td>
<td class="windowbg2" width="20%" align="right">'.$total.'</td>
</tr></table>';
}
}

if( $modSettings['karmaMode'] == 2)
{
echo '<tr>
<td class="catbg" colspan="2">Highest Karma Rating</td>
<td class="catbg" colspan="2">Lowest Karma Rating</td>
</tr>
<tr>
<td class="windowbg" colspan="1">
<img src="'. $settings['images_url']. '/stats_posters.gif" width="20" height="20" />
</td>
<td class="windowbg2">';

foreach($context['gkarma'] as $gkarma)
{
echo '<table border="0" cellpadding="1" cellspacing="0" width="100%"><tr>
<td class="windowbg2" width="80%" align="left">'.
$gkarma['Link']
.'</td>
<td class="windowbg2" width="20%" align="right">+'.$gkarma['Karma'].'</td>
</tr></table>';
}

echo'</td><td class="windowbg" colspan="1">
<img src="'. $settings['images_url']. '/stats_posters.gif" width="20" height="20" />
</td>
<td class="windowbg2">';

foreach($context['bkarma'] as $bkarma)
{
echo '<table border="0" cellpadding="1" cellspacing="0" width="100%">
<tr valign="top"><td class="windowbg2" width="80%" align="left">'.
$bkarma['Link']
.'</td>
<td class="windowbg2" width="20%" align="right">-'.$bkarma['Karma'].'</td>
</tr></table>';
}
}

echo'</tr></td><tr><td class="catbg" colspan="4"><b>', $txt['smf_stats_5'], '</b></td>
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  </tr>
<tr>
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  <td class="windowbg" width="20" valign="middle" align="center"><img src="', $settings['images_url'], '/stats_history.gif" border="0" width="20" height="20" alt="" /></td>
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  <td class="windowbg2" colspan="4">';


It works on SMF 1.1RC2 with TP 0.86b installed.

So having already got code added to Stats.php I set about adapting the code for a block. I've trimmed it down to just Karma Totals (I think) and stopped it messing up the other blocks, but I can't get the totals to display.

echo '<div style="padding: 5px;" class="smalltext">';

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

if( $modSettings['karmaMode'] == 1 )
{
'<table><tr><td class="windowbg2"Ã,  width="80%" align="left">';

foreach($context['htkarma'] as $htkarma)
{
$total = $htkarma['Good'] - $htkarma['Bad'];'</td>
<td class="windowbg2" width="20%" align="right">'.$total.'</td>
</tr></table>';
}
}
echo '</div>';


I think I may need to 'require Stats.php' but when I try to I get a fatal error. Would adding Tau Online's code to TPortal.php work and if so where should it be put?

IchBin

Where's your echo's?

echo '<div style="padding: 5px;" class="smalltext">';

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

if( $modSettings['karmaMode'] == 1 )
{
echo '<table><tr><td class="windowbg2" width="80%" align="left">';

foreach($context['htkarma'] as $htkarma)
{
$total = $htkarma['Good'] - $htkarma['Bad'];
echo '</td><td class="windowbg2" width="20%" align="right">'.$total.'</td></tr></table>';
}
}
echo '</div>';

Nokonium


G6Cad

I think IchBin alterd the code and put in some echos ;)
Seems like it in his post :D

IchBin

Yes, sorry. I posted what I thought the php code should look like.

Nokonium

Ooops, sorry head like a turnip today. Thanks, I'll try it

Nokonium

Parse error: parse error, unexpected T_CLASS in /homepages/6/d119724375/htdocs/Fiddlers-Elbow/Sources/Load.php(1613) : eval()'d code(46) : eval()'d code on line 12

Off to fiddle ...

Nokonium

echo' <table
Messes up the left sidebar blocks

IchBin

Maybe try setting some sizes on your tables or something. Its hard to say when I can't fiddle myself. :)

ontap


i will make a karma block... leave it with me  ;)