SimplePortal
Customization => Custom Coding => Topic started by: Costa on November 10, 2008, 12:05:06 PM
-
It's possible made a php block that show the last 5 users and their avatars?
Thanks to anyone who can do it
Farewell
- Costa
-
That's a block that show the last X user.
//This block work only on SMF 1.1.X
//Insert here how many latest you like :)
$members = 5;
//0 = Comma Seperated, 1 = List form with register date, 2 = Listform with posts
$output = 2;
/* Code Start here change nothing below here if you not know what you do! */
global $db_prefix, $scripturl, $context;
//Fixes :)
$members = (int) $members;
$members = empty($members) || $members < 0 ? 5 : $members;
$outputValues = array(0 => 'list', 1 => 'date');
$outputType = !isset($outputValues[$output]) ? 2 : $outputValues[$output];
//Speed it up a little :) if the user count is lower than members than use this :)
$members = $context['common_stats']['total_members'] <= $members ? $context['common_stats']['total_members'] : $members;
//Load the Karma Good Data
$results = db_query("
SELECT realName, posts, ID_MEMBER, dateRegistered
FROM {$db_prefix}members
WHERE is_activated = 1
ORDER BY dateRegistered DESC
LIMIT $members", __FILE__, __LINE__);
$return = array();
$colorids = array();
while($row = mysql_fetch_assoc($results)) {
$return[] = array(
'id' => $row['ID_MEMBER'],
'name' => $row['realName'],
'href' => $scripturl . '?action=profile;u=' . $row['ID_MEMBER'],
'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] . '">' . $row['realName'] . '</a>',
'posts' => $row['posts'],
'registered' => timeformat($row['dateRegistered']),
);
$colorids[$row['ID_MEMBER']] = $row['ID_MEMBER'];
}
mysql_free_result($results);
//Add colors only on installed SSI Member Color Link for latestMembers
if(function_exists('ssi_loadColors') && !empty($colorids)) {
global $color_profile;
ssi_loadColors($colorids);
foreach($return as $k => $p) {
$profile = $color_profile[$p['id']];
if(!empty($profile)) {
$return[$k]['link'] = $profile['link'];
}
}
}
//Okay some output =)
if(empty($return))
return;
if($outputType == 'list') {
foreach($return as $temp)
$temp_array[] = $temp['link'];
echo '
'.implode(', ', $temp_array);
return;
}
echo '
<table width="100%">';
foreach ($return as $temp) {
echo '
<tr>
<td align="right">
', $temp['link'], '
</td>
<td align="', ($outputType != 'date' ? 'right">'.$temp['posts'] : 'left">'.$temp['registered']), '</td>
</tr>';
}
echo '
</table>';
The Avatar is missing, but i will work on it later, after my work. (Hope i don't forgot it xD).
-
Great! It's that!
Align to the left it's this way:
//This block work only on SMF 1.1.X
//Insert here how many latest you like :)
$members = 5;
//0 = Comma Seperated, 1 = List form with register date, 2 = Listform with posts
$output = 2;
/* Code Start here change nothing below here if you not know what you do! */
global $db_prefix, $scripturl, $context;
//Fixes :)
$members = (int) $members;
$members = empty($members) || $members < 0 ? 5 : $members;
$outputValues = array(0 => 'list', 1 => 'date');
$outputType = !isset($outputValues[$output]) ? 2 : $outputValues[$output];
//Speed it up a little :) if the user count is lower than members than use this :)
$members = $context['common_stats']['total_members'] <= $members ? $context['common_stats']['total_members'] : $members;
//Load the Karma Good Data
$results = db_query("
SELECT realName, posts, ID_MEMBER, dateRegistered
FROM {$db_prefix}members
WHERE is_activated = 1
ORDER BY dateRegistered DESC
LIMIT $members", __FILE__, __LINE__);
$return = array();
$colorids = array();
while($row = mysql_fetch_assoc($results)) {
$return[] = array(
'id' => $row['ID_MEMBER'],
'name' => $row['realName'],
'href' => $scripturl . '?action=profile;u=' . $row['ID_MEMBER'],
'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] . '">' . $row['realName'] . '</a>',
'posts' => $row['posts'],
'registered' => timeformat($row['dateRegistered']),
);
$colorids[$row['ID_MEMBER']] = $row['ID_MEMBER'];
}
mysql_free_result($results);
//Add colors only on installed SSI Member Color Link for latestMembers
if(function_exists('ssi_loadColors') && !empty($colorids)) {
global $color_profile;
ssi_loadColors($colorids);
foreach($return as $k => $p) {
$profile = $color_profile[$p['id']];
if(!empty($profile)) {
$return[$k]['link'] = $profile['link'];
}
}
}
//Okay some output =)
if(empty($return))
return;
if($outputType == 'list') {
foreach($return as $temp)
$temp_array[] = $temp['link'];
echo '
'.implode(', ', $temp_array);
return;
}
echo '
<table width="100%">';
foreach ($return as $temp) {
echo '
<tr>
<td align="left">
', $temp['link'], '
</td>
<td align="', ($outputType != 'date' ? 'right">'.$temp['posts'] : 'left">'.$temp['registered']), '</td>
</tr>';
}
echo '
</table>';
One question, can you retire the post count?
I only want the membres name (or the avatar and the members name)