Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Aiheen aloitti: bobdole2281 - elokuu 25, 2013, 09:21:40 IP

Otsikko: ssi_topPoster help
Kirjoitti: bobdole2281 - elokuu 25, 2013, 09:21:40 IP
Is some variation of this how I can get the top 4 posters:

// Show the top poster's name and profile link.
function ssi_topPoster($topNumber = 1, $output_method = 'echo')


Can I exclude admins?
Otsikko: Re: ssi_topPoster help
Kirjoitti: Arantor - elokuu 25, 2013, 09:29:32 IP
Well, passing the first parameter as 4 would get the top 4, but you'd have to rewrite the main query to exclude admins. And it'll suck for performance too.

$request = $smcFunc['db_query']('', '
SELECT id_member, real_name, posts
FROM {db_prefix}members
WHERE id_group != 1 AND FIND_IN_SET(1, additional_groups) = 0
ORDER BY posts DESC
LIMIT ' . $topNumber,
array(
)
);
Otsikko: Re: ssi_topPoster help
Kirjoitti: Biology Forums - elokuu 26, 2013, 12:48:46 AP
In your template,

try:

ssi_topPoster(4);
Otsikko: Re: ssi_topPoster help
Kirjoitti: Arantor - elokuu 26, 2013, 05:33:45 IP
Firstly, you don't put SSI functions in the template, mostly because you should not EVER be calling SSI inside an SMF context (hint: that's why one of the very first lines checks if SMF is already loaded and tries to exit gracefully)

Secondly, that doesn't actually answer the OP's question, i.e. how to do it but also exclude administrators.
Otsikko: Re: ssi_topPoster help
Kirjoitti: NIAB - elokuu 27, 2013, 08:23:44 IP
I use the following code for my top poster

It helps grab a few other things :)

Koodi ("cTopPoster") [Valitse]

function ssi_ctopPoster($topNumber, $output_method)
{
global $smcFunc, $scripturl, $modSettings, $settings;

// Height and width of avatar
$width = '50px';
$height = '50px';
// Number of top posters displayed
$topNumber = 5;

// Find the latest poster.
$request = $smcFunc['db_query']('', '
SELECT mem.id_member, mem.show_online, mem.real_name, mem.posts, mem.avatar, a.id_attach, a.attachment_type, a.filename
FROM ({db_prefix}members as mem)
LEFT JOIN {db_prefix}attachments AS a ON (a.id_member = mem.id_member)
WHERE show_online = 1
ORDER BY posts DESC
LIMIT {int:limit}',
array('limit' => $topNumber)
);

$users = array();

while ($row = $smcFunc['db_fetch_assoc']($request))
{
$users[] = array(
'id' => $row['id_member'],
'name' => $row['real_name'],
'href' => $scripturl . '?action=profile;u=' . $row['id_member'],
'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>',
'posts' => $row['posts'],
'show' => $row['show_online'],
'avatar' => array(
    'image' => empty($row['avatar']) ? ($row['id_attach'] > 0 ? 'src="' . (empty($row['attachment_type']) ? $scripturl . '?action=dlattach;attach=' . $row['id_attach'] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $row['filename']) . '" alt="" border="0" width="'.$width.'" height="'.$height.'" title="'.$row['real_name'].'" />' : '') : (stristr($row['avatar'], 'http://') ? 'src="' . $row['avatar'] . '" alt="" border="0" width="'.$width.'" height="'.$height.'" title="'.$row['real_name'].'" />' : 'src="' . $modSettings['avatar_url'] . '/' . htmlspecialchars($row['avatar']) . '" alt="" border="0" width="'.$width.'" height="'.$height.'" title="'.$row['real_name'].'" />'),
    ),
);
}

$smcFunc['db_free_result']($request);

// Output our array of users with avatar, posts, and name

$i = 0;
$len = count($array);
foreach($users as $user) {
    if ($i == 0) {
echo'<a href="'.$user['href'].'">';
        echo'<table id="cTopT" class="fp_news_link" width="100%" ><td width="42px">';
echo '',empty($user['avatar']['image']) ? '<a href="'.$user['href'].'"><img src="'.$settings['images_url'].'/noavatar.gif" width="'.$width.'" height="'.$height.'" alt="" title="'.$user['name'].'" /></a>' : '<a href="'.$user['href'].'"><img '.$user['avatar']['image'].'</a>';
echo '
</td>
<td><h5 style="margin: 4px;">'.$user['link'].'</h5><h5 style="margin: 4px;">Posts: '. $user['posts'] .'';
echo'</td></table>';
echo'</a>';

$i++;
     } else if ($i == 1) {
echo'<a href="'.$user['href'].'">';
    echo'<table id="cTopT" width="100%" class="fp_news_link"><td width="42px">';
echo '',empty($user['avatar']['image']) ? '<a href="'.$user['href'].'"><img src="'.$settings['images_url'].'/noavatar.gif" width="'.$width.'" height="'.$height.'" alt="" title="'.$user['name'].'" /></a>' : '<a href="'.$user['href'].'"><img '.$user['avatar']['image'].'</a>';
echo '
</td>
<td><h5 style="margin: 4px;">'.$user['link'].'</h5><h5 style="margin: 4px;">Posts: '. $user['posts'] .'';
echo'</td></table>';
echo'</a>';
}

}


Just use this to get it to show :)

Koodi ("Output") [Valitse]

ssi_ctopPoster('5', 'echo');


It shows the top 5 Posters :)

Same thing as a the default, but It gets a little more.
Here's what Mine looks like

(https://www.simplemachines.org/community/proxy.php?request=http%3A%2F%2Fi.imgur.com%2FUrIjSrf.png&hash=87bded466a91a37b2f15b993cb7098179c40c3fe)

When it comes to excluding admins, you should keep them in there. It helps increase competition between users and staff :) Makes the position at the top ever so sweet

Otsikko: Re: ssi_topPoster help
Kirjoitti: thisisedy - toukokuu 13, 2014, 04:10:55 AP
Lainaus käyttäjältä: NIAB - elokuu 27, 2013, 08:23:44 IP

Koodi ("cTopPoster") [Valitse]

function ssi_ctopPoster($topNumber, $output_method)
{
global $smcFunc, $scripturl, $modSettings, $settings;

// Height and width of avatar
$width = '50px';
$height = '50px';
// Number of top posters displayed
$topNumber = 5;

// Find the latest poster.
$request = $smcFunc['db_query']('', '
SELECT mem.id_member, mem.show_online, mem.real_name, mem.posts, mem.avatar, a.id_attach, a.attachment_type, a.filename
FROM ({db_prefix}members as mem)
LEFT JOIN {db_prefix}attachments AS a ON (a.id_member = mem.id_member)
WHERE show_online = 1
ORDER BY posts DESC
LIMIT {int:limit}',
array('limit' => $topNumber)
);

$users = array();

while ($row = $smcFunc['db_fetch_assoc']($request))
{
$users[] = array(
'id' => $row['id_member'],
'name' => $row['real_name'],
'href' => $scripturl . '?action=profile;u=' . $row['id_member'],
'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>',
'posts' => $row['posts'],
'show' => $row['show_online'],
'avatar' => array(
    'image' => empty($row['avatar']) ? ($row['id_attach'] > 0 ? 'src="' . (empty($row['attachment_type']) ? $scripturl . '?action=dlattach;attach=' . $row['id_attach'] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $row['filename']) . '" alt="" border="0" width="'.$width.'" height="'.$height.'" title="'.$row['real_name'].'" />' : '') : (stristr($row['avatar'], 'http://') ? 'src="' . $row['avatar'] . '" alt="" border="0" width="'.$width.'" height="'.$height.'" title="'.$row['real_name'].'" />' : 'src="' . $modSettings['avatar_url'] . '/' . htmlspecialchars($row['avatar']) . '" alt="" border="0" width="'.$width.'" height="'.$height.'" title="'.$row['real_name'].'" />'),
    ),
);
}

$smcFunc['db_free_result']($request);

// Output our array of users with avatar, posts, and name

$i = 0;
$len = count($array);
foreach($users as $user) {
    if ($i == 0) {
echo'<a href="'.$user['href'].'">';
        echo'<table id="cTopT" class="fp_news_link" width="100%" ><td width="42px">';
echo '',empty($user['avatar']['image']) ? '<a href="'.$user['href'].'"><img src="'.$settings['images_url'].'/noavatar.gif" width="'.$width.'" height="'.$height.'" alt="" title="'.$user['name'].'" /></a>' : '<a href="'.$user['href'].'"><img '.$user['avatar']['image'].'</a>';
echo '
</td>
<td><h5 style="margin: 4px;">'.$user['link'].'</h5><h5 style="margin: 4px;">Posts: '. $user['posts'] .'';
echo'</td></table>';
echo'</a>';

$i++;
     } else if ($i == 1) {
echo'<a href="'.$user['href'].'">';
    echo'<table id="cTopT" width="100%" class="fp_news_link"><td width="42px">';
echo '',empty($user['avatar']['image']) ? '<a href="'.$user['href'].'"><img src="'.$settings['images_url'].'/noavatar.gif" width="'.$width.'" height="'.$height.'" alt="" title="'.$user['name'].'" /></a>' : '<a href="'.$user['href'].'"><img '.$user['avatar']['image'].'</a>';
echo '
</td>
<td><h5 style="margin: 4px;">'.$user['link'].'</h5><h5 style="margin: 4px;">Posts: '. $user['posts'] .'';
echo'</td></table>';
echo'</a>';
}

}


Just use this to get it to show :)

Koodi ("Output") [Valitse]

ssi_ctopPoster('5', 'echo');


This is a new function or its SSI related? Where do i need to place this to show the top5 posters on boardindex ? Tried Load.php but i get blank page forum after . Same thing pasting the code in boardindex.template file .
Using 2.0.7 with no portal mods .