TinyPortal

Development => Block Codes => Topic started by: Xarcell on November 08, 2005, 09:25:52 PM

Title: Random User Block
Post by: Xarcell on November 08, 2005, 09:25:52 PM
Anyone know a way to create a random user block? Maybe even membergroup based?

-X
Title: Re: Random User Block
Post by: Pierse on November 08, 2005, 11:24:51 PM
This would be great!
Title: Re: Random User Block
Post by: Sakuragi on November 12, 2005, 03:07:34 PM
take a look on this :
http://www.simplemachines.org/community/index.php?topic=13676.msg127749#msg127749
Title: Re: Random User Block
Post by: houston on November 12, 2005, 04:59:48 PM
Quote from: Sakuragi on November 12, 2005, 03:07:34 PM
take a look on this :
http://www.simplemachines.org/community/index.php?topic=13676.msg127749#msg127749

What kind of block would you use to use the code?
Title: Re: Random User Block
Post by: snork13 on November 12, 2005, 05:31:27 PM
Quote from: houston on November 12, 2005, 04:59:48 PM
Quote from: Sakuragi on November 12, 2005, 03:07:34 PM
take a look on this :
http://www.simplemachines.org/community/index.php?topic=13676.msg127749#msg127749

What kind of block would you use to use the code?

php block
Title: Re: Random User Block
Post by: houston on November 12, 2005, 08:30:26 PM
I tried that Snork13 and all I got was the tiltle bar with nothing below it.
Title: Re: Random User Block
Post by: IchBin on November 12, 2005, 10:07:35 PM
Can you post the code you put in?
Title: Re: Random User Block
Post by: houston on November 12, 2005, 10:22:47 PM
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>';
}
Title: Re: Random User Block
Post by: 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
Title: Re: Random User Block
Post by: houston on November 13, 2005, 04:33:35 AM
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.
Title: Re: Random User Block
Post by: houston on November 13, 2005, 04:48:00 AM
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
Title: Re: Random User Block
Post by: 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?
Title: Re: Random User Block
Post by: houston on November 13, 2005, 05:18:41 AM
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
Title: Re: Random User Block
Post by: bloc on November 13, 2005, 09:04:11 AM
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.
Title: Re: Random User Block
Post by: houston on November 14, 2005, 12:08:43 AM
Thanks to Xarcell, I was able to get into the DB and delete the wayward block.
Title: Re: Random User Block
Post by: Pierse on November 14, 2005, 10:03:35 AM
Works Great!ÂÃ,  Thanks for the idea!  Would even be cool to be part of the stats (Users Online)
Title: Re: Random User Block
Post by: elpvn on March 01, 2006, 09:27:38 AM
I like this solution from Senkusha in SMF community (http://www.simplemachines.org)

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 !Ã,  :)
Title: Re: Random User Block
Post by: Xarcell on March 07, 2006, 09:27:39 PM
Anyway to do this by membergroup?
Title: Re: Random User Block
Post by: firefly on March 08, 2006, 11:12:36 PM
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.
Title: Re: Random User Block
Post by: Mitch on March 15, 2006, 12:06:52 AM
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.
Title: Re: Random User Block
Post by: Embrace on October 22, 2007, 05:11:48 AM
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
Title: Re: Random User Block
Post by: JPDeni on October 22, 2007, 12:43:16 PM
http://www.tinyportal.net/index.php?topic=19521
Title: Re: Random User Block
Post by: phfire on February 10, 2008, 06:42:25 AM
How do I filter out those members without avatars? Display only those with avatars. May I know the code please. Thanks.
Title: Re: Random User Block
Post by: JPDeni on February 10, 2008, 11:10:06 AM
What code are you using?
Title: Re: Random User Block
Post by: phfire on February 10, 2008, 11:30:14 AM
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
Title: Re: Random User Block
Post by: JPDeni on February 10, 2008, 12:41:47 PM
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__);
Title: Re: Random User Block
Post by: 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! :)
Title: Re: Random User Block
Post by: Ken. on February 10, 2008, 02:11:42 PM
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.  :)