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

Recent

Welcome to TinyPortal. Please login or sign up.

May 17, 2024, 07:32:19 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: 107
  • Online ever: 3,540 (September 03, 2022, 01:38:54 AM)
Users Online
  • Users: 1
  • Guests: 64
  • Total: 65
  • @rjen

Random User Block

Started by Xarcell, November 08, 2005, 09:25:52 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Xarcell

Anyone know a way to create a random user block? Maybe even membergroup based?

-X

Pierse





houston

I tried that Snork13 and all I got was the tiltle bar with nothing below it.

IchBin

Can you post the code you put in?

houston

Quote from: IchBinÃ,â,,¢ on November 12, 2005, 10:07:35 PM
Can you post the code you put in?

Here it is.

// Shows a list of recent users:  YY Guests, ZZ Users and then a list...
function ssi_whosRecent($output_method = 'echo')
{
global $scripturl, $db_prefix, $txt, $modSettings;

$midnight = ((date("U") - (date("H") * 3600)) - (date("i") * 60));
// Load the users online for the past 24 hours.
$result = db_query("
SELECT
mem.ID_MEMBER, mem.realName, mem.memberName, mem.ID_GROUP, mem.showOnline, mem.avatar, mem.lastLogin, mem.posts,
mg.onlineColor
FROM {$db_prefix}members AS mem
LEFT JOIN {$db_prefix}membergroups AS mg ON (mg.ID_GROUP = mem.ID_GROUP OR (mem.ID_GROUP = 0 AND mg.ID_GROUP = mem.ID_POST_GROUP))
WHERE mem.lastLogin >= '$midnight'
ORDER BY mem.realName
LIMIT 5", __FILE__, __LINE__);

$return['users'] = array();
$return['guests'] = 0;
$return['hidden'] = 0;

while ($tmp = mysql_fetch_assoc($result))
{
if (!isset($tmp['realName']))
{
$return['guests']++;
continue;
}
elseif (empty($tmp['showOnline']))
{
$return['hidden']++;
continue;
}

$link = '<table border="0"><tr>';

// The user Avatar...
if ($tmp['avatar'] == '')
{
$AvatarReq = db_query ("SELECT * FROM {$db_prefix}attachments WHERE ID_MEMBER = '$tmp[ID_MEMBER]'", __FILE__, __LINE__);
$AvatarRes = mysql_fetch_assoc($AvatarReq);
if (mysql_num_rows ($AvatarReq) == 1)
$link .= '<td></td><table>';
$link .= '
<td valign="middle" width="40"><img src="' . $scripturl . '?action=dlattach;id=' . $AvatarRes['ID_ATTACH'] . ';type=avatar" height="40"></td><td><table>';
}
elseif (strtoupper(substr($tmp['avatar'],0,7)) == 'HTTP://')
$link .= '
<td align="center" valign="middle"><img src="' . $tmp['avatar'] . '" height="40"></td><td><table>';
else
$link .= '
<td align="center" valign="middle"><img src="' . $modSettings['avatar_url'] . '/' . $tmp['avatar'] . '" height="40"></td><td><table>';

// Some basic color coding...
if (!empty($row['onlineColor']))
$link .= '
<tr>
<td align="left" valign="top" nowrap><font size="1" face="Tahoma"><a href="' . $scripturl . '?action=profile;u=' . $tmp['ID_MEMBER'] . '" style="color: ' . $tmp['onlineColor'] . ';">' . $tmp['realName'] . '</a></font></td>
</tr>';
else
$link .= '
<tr>
<td align="left" valign="top" nowrap><font size="1" face="Tahoma"><a href="' . $scripturl . '?action=profile;u=' . $tmp['ID_MEMBER'] . '">' . $tmp['realName'] . '</a></font></td>
</tr>';
// Number of total posts
$link .= '<tr>
<td align="left" valign="top"><font size="1" face="Tahoma">Posts:&nbsp;' . $tmp['posts'] . '</font></td>
</tr>';
// Time the member last logged in
$link .= '<tr>
<td align="left" valign="top"><font size="1" face="Tahoma">Last On:&nbsp;' . date("H:i", $tmp['lastLogin']) . '</font></td>
</tr></table></td>
</tr></table>';


$return['users'][] = array(
'id' => $tmp['ID_MEMBER'],
'username' => $tmp['memberName'],
'name' => $tmp['realName'],
'group' => $tmp['ID_GROUP'],
'href' => $scripturl . '?action=profile;u=' . $tmp['ID_MEMBER'],
'link' => $link,
'is_last' => false
);
}
mysql_free_result($result);

$return['num_users'] = count($return['users']) + $return['hidden'];
$return['total_users'] = $return['num_users'] + $return['guests'];

if (!empty($return['users']))
$return['users'][count($return['users']) - 1]['is_last'] = true;

if ($output_method != 'echo')
return $return;

echo '
', $return['guests'], ' ', $return['guests'] == 1 ? $txt['guest'] : $txt['guests'], ', ', $return['num_users'], ' ', $return['num_users'] == 1 ? $txt['user'] : $txt['users'], $return['hidden'] > 0 ? ' (' . $return['hidden'] . ' ' . $txt['hidden'] . ')' : '', '

';

echo '<table align="left" border="0">';
foreach ($return['users'] as $user)
echo $user['link'], !$user['is_last'] ? '' : '';
echo '</table>';
}

Sakuragi

you should put this code on SSI.php just below ssi_whosOnline function
and create a new php bloc with this:
ssi_whosRecent

houston

Quote from: Sakuragi on November 12, 2005, 11:24:26 PM
you should put this code on SSI.php just below ssi_whosOnline function
and create a new php bloc with this:
ssi_whosRecent

Thanks I will give that a try.

houston

Oh Crap know what have I done.

Lookat what has happened.

Fatal error: Call to undefined function: ssi_whosrecent() in /home/eaglebay/public_html/forum/Sources/Load.php(1643) : eval()'d code(32) : eval()'d code on line 1

IchBin

You're going to have to call your host and have them reinstall the operating system... :P
What exactly did you do to get that error? What kind of block? What did you put in the block?

houston

#12
Quote from: IchBinâââ,¬Å¾Ã,¢ on November 13, 2005, 04:53:22 AM
You're going to have to call your host and have them reinstall the operating system... :P
What exactly did you do to get that error? What kind of block? What did you put in the block?

I inserted the code that I posted a couple of posts back into the SSI.php file where suggested by Sakuragi Then build a phpblock and inserted this code

ssi_whosRecent

It gave me a parse error in the block.

I went back to the phpblock and edited it and replaced

ssi_whosRecent with with ssi_whosRecent();

That when I got the fatal error.

I have a recent back up of my forum. Could I just reload the files from the back up? And if So which ones.

Everything else works except TP.


This is the error that I am getting in the smf error logs

http://www.eaglebaycamp.com/forum/index.php?action=tpadmin;blockeditl=39 
Block does not exist

Thanks

bloc

Be very accurate in the name of the function. It seems you have uppercase/lowercase mix in the function name, but when you call it you use all lowercase.

houston

Thanks to Xarcell, I was able to get into the DB and delete the wayward block.

Pierse

Works Great!ÂÃ,  Thanks for the idea!  Would even be cool to be part of the stats (Users Online)

elpvn

I like this solution from Senkusha in SMF community

Quote from: SenkushaHere is the code to add the avatars to the listing. Note this code is for all Online members:

Open BoardIndex.php and find:


// Load the users online right now.
$result = db_query("
SELECT
lo.ID_MEMBER, lo.logTime, mem.realName, mem.memberName, mem.showOnline,
mg.onlineColor, mg.ID_GROUP, mg.groupName
FROM {$db_prefix}log_online AS lo
LEFT JOIN {$db_prefix}members AS mem ON (mem.ID_MEMBER = lo.ID_MEMBER)
LEFT JOIN {$db_prefix}membergroups AS mg ON (mg.ID_GROUP = mem.ID_GROUP OR (mem.ID_GROUP = 0 AND mg.ID_GROUP = mem.ID_POST_GROUP))", __FILE__, __LINE__);

$context['users_online'] = array();
$context['list_users_online'] = array();
$context['online_groups'] = array();
$context['num_guests'] = 0;
$context['num_users_hidden'] = 0;
while ($row = mysql_fetch_assoc($result))
{
if (!isset($row['realName']))
{
$context['num_guests']++;
continue;
}
elseif (empty($row['showOnline']))
{
$context['num_users_hidden']++;
continue;
}


Replace it with the following code:

// Load the users online right now.
$result = db_query("
SELECT
lo.ID_MEMBER, lo.logTime, mem.realName, mem.memberName, mem.showOnline, mem.avatar,
mg.onlineColor, mg.ID_GROUP, mg.groupName
FROM {$db_prefix}log_online AS lo
LEFT JOIN {$db_prefix}members AS mem ON (mem.ID_MEMBER = lo.ID_MEMBER)
LEFT JOIN {$db_prefix}membergroups AS mg ON (mg.ID_GROUP = mem.ID_GROUP OR (mem.ID_GROUP = 0 AND mg.ID_GROUP = mem.ID_POST_GROUP))", __FILE__, __LINE__);


$context['users_online'] = array();
$context['list_users_online'] = array();
$context['online_groups'] = array();
$context['num_guests'] = 0;
$context['num_users_hidden'] = 0;
while ($row = mysql_fetch_assoc($result))
{
if (!isset($row['realName']))
{
$context['num_guests']++;
continue;
}
elseif (empty($row['showOnline']))
{
$context['num_users_hidden']++;
continue;
}
// The user Avatar...
if ($row['avatar'] == '')
$link = '&nbsp;<br>';
elseif (strtoupper(substr($row['avatar'],0,7)) == 'HTTP://')
$link = '<img src="' . $row['avatar'] . '" height="40"><br>';
else
$link = '<img src="' . $modSettings['avatar_url'] . '/' . $row['avatar'] . '" height="40"><br>';

// Some basic color coding...
if (!empty($row['onlineColor']))
$link .= '<a href="' . $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] . '" style="color: ' . $row['onlineColor'] . ';">' . $row['realName'] . '</a>';
else
$link .= '<a href="' . $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] . '">' . $row['realName'] . '</a>';



And delete the following (repeated lines at the bottom now):

// Some basic color coding...
if (!empty($row['onlineColor']))
$link .= '<a href="' . $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] . '" style="color: ' . $row['onlineColor'] . ';">' . $row['realName'] . '</a>';
else
$link .= '<a href="' . $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] . '">' . $row['realName'] . '</a>';


Now if you want to limit this query to only five members, change this:

$result = db_query("
SELECT
lo.ID_MEMBER, lo.logTime, mem.realName, mem.memberName, mem.showOnline, mem.avatar,
mg.onlineColor, mg.ID_GROUP, mg.groupName
FROM {$db_prefix}log_online AS lo
LEFT JOIN {$db_prefix}members AS mem ON (mem.ID_MEMBER = lo.ID_MEMBER)
LEFT JOIN {$db_prefix}membergroups AS mg ON (mg.ID_GROUP = mem.ID_GROUP OR (mem.ID_GROUP = 0 AND mg.ID_GROUP = mem.ID_POST_GROUP))", __FILE__, __LINE__);


to this:

   $result = db_query("
SELECT
lo.ID_MEMBER, lo.logTime, mem.realName, mem.memberName, mem.showOnline, mem.avatar,
mg.onlineColor, mg.ID_GROUP, mg.groupName
FROM {$db_prefix}log_online AS lo
LEFT JOIN {$db_prefix}members AS mem ON (mem.ID_MEMBER = lo.ID_MEMBER)
LEFT JOIN {$db_prefix}membergroups AS mg ON (mg.ID_GROUP = mem.ID_GROUP OR (mem.ID_GROUP = 0 AND mg.ID_GROUP = mem.ID_POST_GROUP)) LIMIT 5", __FILE__, __LINE__);


That should do the trick for you.Ã,  Make sure you make a backup copy of the BoardIndex.php file!Ã,  I have tested this on my board, but since I only had myself active at the time, I can not gauntee that it works.

Let me know if you have any problems.

That's works very well !Ã,  :)

Xarcell

Anyway to do this by membergroup?

firefly

I tried, as per Houston's effort, to use Sakuragi's code and call it in a php block - taking care to follow Bloc's advice on case - yet had the same error, which reported the wrong case. It's easy to delete the error: reinstate the orginal code and delete the block in the db. But as to why it failed, I don't know. Perhaps a working example of the modded SSI would be useful.

Mitch

Ok I would like to go about doing this but I am pretty braindead when it comes to this kind of thing.

I need some one who will either do it for me or at least talk me through it.

Embrace

Any way to get somthing like this that displays random members avatars with a link to the profile of the member?

I want somthing like phpizabi has :)

http://demo.phpizabi.net/

check the vary bottom of that page


Thanks,
Embrace


phfire

How do I filter out those members without avatars? Display only those with avatars. May I know the code please. Thanks.

JPDeni


phfire

#24
this one

global $db_prefix, $memberContext;

// How many members we want?
$members_limit = 7;
// Just special groups get to be part of the block.
// To select Admins and moderators would be like $groups = array(1, 2);
$groups = array();
// Avatar images.
$avatarImage = '';

$group_clause = empty($groups) ? '1' : 'ID_GROUP IN(' . implode(',', $groups) . ')';

// Lets get the ID's of the members we want.
$request = db_query("
SELECT ID_MEMBER
FROM {$db_prefix}members
WHERE $group_clause
ORDER BY RAND()
LIMIT $members_limit", __FILE__, __LINE__);
$members = array();
while ($row = mysql_fetch_assoc($request))
$members[] = $row['ID_MEMBER'];
mysql_free_result($request);

// Load the data for these members.
loadMemberData($members);

// Now get the context.
foreach ($members as $member)
loadMemberContext($member);

echo '
<table valign="middle" align="center">
<tr>';
foreach ($memberContext as $member)
{
echo '
<td>
', empty($member['avatar']['image']) ? '<img src="no avatar pic" />' : $member['avatar']['image'], '<br />
', $member['link'], '
</td>';
}
echo '
</tr>
</table>';


EDIT: placed the code in a code box for you... ken

JPDeni

It's a whole lot easier to read code if you use the "code" tags. You can access them by clicking the button that has a # on it.

To only show users that have avatars, change


$request = db_query("
   SELECT ID_MEMBER
   FROM {$db_prefix}members
   WHERE $group_clause
   ORDER BY RAND()
   LIMIT $members_limit", __FILE__, __LINE__);


to


$request = db_query("
   SELECT ID_MEMBER
   FROM {$db_prefix}members
   WHERE $group_clause
   AND  LENGTH( `avatar` ) >0
   ORDER BY RAND()
   LIMIT $members_limit", __FILE__, __LINE__);

phfire

oh ok..sorry for the dirty post. i'll do it right next time. thanks for helping me out! :)

Ken.

Quote from: phfire on February 10, 2008, 01:43:59 PM
oh ok..sorry for the dirty post. i'll do it right next time. thanks for helping me out! :)

phfire, its fixed for you now but for future reference you can do corrections to your post be clicking the 'Modify' link inside the post in question.  :)
" If everything seems under control, you're not going fast enough." - Mario Andretti
Yesterday When I was Young.