TinyPortal

Development => Block Codes => Topic started by: IchBin on December 01, 2008, 02:18:57 AM

Title: [Block] Avatar of Users Online
Post by: IchBin on December 01, 2008, 02:18:57 AM
This php code snippet will only work in a phpbox type block. It has a configurable column setting so it can fit a top/bottom or side block. You can also set a time limit on how far back you want to show users online i.e. 15 minutes, 1hour, 1day. All of the configurable options are put in the top, including any CSS changes you want to make. If your user avatars are larger or smaller than 100x100 pixels wide, adjust the CSS accordingly in the code. A default avatar is set if the user does not have an avatar. This assumes there is a file named default_avatar.gif in your themes images directory.


global $memberContext, $db_prefix, $scripturl, $modSettings;

/* ###  CONFIGURATION OPTIONS  ### */
// Set time limit using seconds
// 1 hour = 3600
// 1 day = 84600
$timelimit = 3600;

// Set $columns to the amount of columns you need
// You set this depending on whether you want it in a side block or a top/bottom block.
$columns = 5;

// Set the height and width of avatars
// This will resize the avatars to be more uniform
$width = "40px";
$height = "40px";

// Set or change the style of all the elements
echo '<style type="text/css">
.avatar_column
{
border: 0;
}
.avatar_column td
{
height: 100px;
width: 100px;
overflow: hidden;
text-align: center;
vertical-align: top;
}
.default
{
border: 2px solid black;
}
.he
{
border: 2px solid blue;
}
.she
{
border: 2px solid pink;
}
</style>';

/* ###  END CONFIGURATION OPTIONS  ### */

// Load all users who have logged in within $timelimit
$result = db_query("
SELECT mem.ID_MEMBER, mem.showOnline, mem.lastLogin, mem.realName, mem.avatar, mem.gender, a.ID_ATTACH, a.attachmentType, a.filename
FROM ({$db_prefix}members as mem)
LEFT JOIN {$db_prefix}attachments AS a ON (a.ID_MEMBER = mem.ID_MEMBER)
WHERE mem.lastLogin > (UNIX_TIMESTAMP() - $timelimit)
ORDER BY mem.lastLogin DESC", __FILE__, __LINE__);

$users = array();

// Loop through the results to display the users avatar
while ($row = mysql_fetch_assoc($result))
{
    $users[$row['ID_MEMBER']] = array (
    'id' => $row['ID_MEMBER'],
    'href' => $scripturl.'?action=profile;u='.$row['ID_MEMBER'],
    'name' => $row['realName'],
    'show' => $row['showOnline'],
'gender' => $row['gender'],
    'avatar' => array(
    'image' => $row['avatar'] == '' ? ($row['ID_ATTACH'] > 0 ? 'src="' . (empty($row['attachmentType']) ? $scripturl . '?action=dlattach;attach=' . $row['ID_ATTACH'] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $row['filename']) . '" alt="" border="0" width="'.$width.'" height="'.$height.'" title="'.$row['realName'].'" />' : '') : (stristr($row['avatar'], 'http://') ? 'src="' . $row['avatar'] . '" alt="" border="0" width="'.$width.'" height="'.$height.'" title="'.$row['realName'].'" />' : 'src="' . $modSettings['avatar_url'] . '/' . htmlspecialchars($row['avatar']) . '" alt="" border="0" width="'.$width.'" height="'.$height.'" title="'.$row['realName'].'" />'),
    ),
    );
}

mysql_free_result($result);

echo '
<table class="avatar_column">
<tr>';

$counter = 0;

foreach ($users as $user)
{
if ($user['show'] == 1)
{
switch ($user['gender'])
{
case 0:
$css = "default";
break;
case 1:
$css = "he";
break;
case 2:
$css = "she";
break;
}
if ($counter < $columns)
{
echo '
    <td>',empty($user['avatar']['image']) ? '<a href="'.$user['href'].'"><img class="'.$css.'" src="'.$settings['images_url'].'/default_avatar.gif" width="'.$width.'" height="'.$height.'" alt="" title="'.$user['name'].'" /></a><h6>'.$user['name'].'</h6></td>' : '<a href="'.$user['href'].'"><img class="'.$css.'" '.$user['avatar']['image'].'</a><h6>'.$user['name'].'</h6></td>';
    $counter++;
}
else
{
echo '
</tr>
<tr>
<td>',empty($user['avatar']['image']) ? '<a href="'.$user['href'].'"><img class="'.$css.'" src="'.$settings['images_url'].'/default_avatar.gif" width="'.$width.'" height="'.$height.'" alt="" /></a><h6>'.$user['name'].'</h6></td>' : '<a href="'.$user['href'].'"><img class="'.$css.'" '.$user['avatar']['image'].'</a><h6>'.$user['name'].'</h6></td>';
$counter = 1;
}
}
}

echo '
</tr>
</table>';



This next bit of code creates a single row with the avatars scrolling to the left. There is no column configuration for this code as it will scroll all the online users within the configurable time limit to scroll in the block.
global $memberContext, $db_prefix, $scripturl, $modSettings;

/* ###  CONFIGURATION OPTIONS  ### */
// Set time limit using seconds
// 1 hour = 3600
// 1 day = 84600
$timelimit = 3600;

// Set the height and width of avatars
// This will resize the avatars to be more uniform
$width = "40px";
$height = "40px";

// Set or change the style of all the elements
echo '<style type="text/css">
.avatar_column
{
border: 0;
}
.avatar_column td
{
height: 60px;
width: 60px;
overflow: hidden;
text-align: center;
vertical-align: top;
}
.default
{
border: 2px solid black;
}
.he
{
border: 2px solid blue;
}
.she
{
border: 2px solid pink;
}
</style>';

/* ###  END CONFIGURATION OPTIONS  ### */

// Load all users who have logged in within $timelimit
$result = db_query("
SELECT mem.ID_MEMBER, mem.showOnline, mem.lastLogin, mem.realName, mem.avatar, mem.gender, a.ID_ATTACH, a.attachmentType, a.filename
FROM ({$db_prefix}members as mem)
LEFT JOIN {$db_prefix}attachments AS a ON (a.ID_MEMBER = mem.ID_MEMBER)
WHERE mem.lastLogin > (UNIX_TIMESTAMP() - $timelimit)
ORDER BY mem.lastLogin DESC", __FILE__, __LINE__);

$users = array();

// Loop through the results to display the users avatar
while ($row = mysql_fetch_assoc($result))
{
    $users[$row['ID_MEMBER']] = array (
    'id' => $row['ID_MEMBER'],
    'href' => $scripturl.'?action=profile;u='.$row['ID_MEMBER'],
    'name' => $row['realName'],
    'show' => $row['showOnline'],
'gender' => $row['gender'],
    'avatar' => array(
    'image' => $row['avatar'] == '' ? ($row['ID_ATTACH'] > 0 ? 'src="' . (empty($row['attachmentType']) ? $scripturl . '?action=dlattach;attach=' . $row['ID_ATTACH'] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $row['filename']) . '" alt="" border="0" width="'.$width.'" height="'.$height.'" title="'.$row['realName'].'" />' : '') : (stristr($row['avatar'], 'http://') ? 'src="' . $row['avatar'] . '" alt="" border="0" width="'.$width.'" height="'.$height.'" title="'.$row['realName'].'" />' : 'src="' . $modSettings['avatar_url'] . '/' . htmlspecialchars($row['avatar']) . '" alt="" border="0" width="'.$width.'" height="'.$height.'" title="'.$row['realName'].'" />'),
    ),
    );
}

mysql_free_result($result);

echo '
<marquee direction="left">
<table class="avatar_column">
<tr>';

foreach ($users as $user)
{
if ($user['show'] == 1)
{
switch ($user['gender'])
{
case 0:
$css = "default";
break;
case 1:
$css = "he";
break;
case 2:
$css = "she";
break;
}
echo '
<td>',(empty($user['avatar']['image']) ? '<a href="'.$user['href'].'"><img class="'.$css.'" src="'.$settings['images_url'].'/default_avatar.gif" width="'.$width.'" height="'.$height.'" alt="" title="'.$user['name'].'" /></a><h6>'.$user['name'].'</h6>' : '<a href="'.$user['href'].'"><img class="'.$css.'" '.$user['avatar']['image'].'</a><h6>'.$user['name'].'</h6>'),'</td>';

}
}

echo '
</tr>
</table>
</marquee>';
Title: Re: [Block] Avatar of Users Online
Post by: fl4pj4ck on December 01, 2008, 03:55:08 AM
not working, showing all avatars instead
Title: Re: [Block] Avatar of Users Online
Post by: IchBin on December 01, 2008, 02:43:25 PM
Do you mean it's showing all users?

--edit--

Bah... I just realized I left the query messed up from testing it.. Will fix it as soon as I get some things done today.
Title: Re: [Block] Avatar of Users Online
Post by: IchBin on December 01, 2008, 03:07:27 PM
Ok that should work now. I forgot to mention I put in the default avatar. You can rename it if you need. This snippet expects a default_avatar.gif to be in the images folder of any theme that you're using.
Title: Re: [Block] Avatar of Users Online
Post by: fl4pj4ck on December 01, 2008, 03:47:39 PM
almost perfect, but it needs some polishing. i.e. what if the avatars have different sizes? could you please update it with "height" and "width" options? trier it myself and with this code:

--remove code by IchBin--

looks like this (see pic attached), for some reason not all pics are resized, can you help me with that?

Title: Re: [Block] Avatar of Users Online
Post by: JPDeni on December 01, 2008, 03:51:31 PM
You misspelled "height".


'<img width=35 heigth=35


should be


'<img width=35 height=35
Title: Re: [Block] Avatar of Users Online
Post by: IchBin on December 01, 2008, 03:58:53 PM
Thanks Deni.

I'll add the height and width to the settings for a better all around look by default.

I've updated the first post.
Title: Re: [Block] Avatar of Users Online
Post by: fl4pj4ck on December 01, 2008, 04:23:25 PM
didnt help too much:

EDIT: wokrs ok now, I have pasted the wrong code :)

thanks guys :)
Title: Re: [Block] Avatar of Users Online
Post by: fl4pj4ck on December 01, 2008, 04:35:46 PM
TWO more things: the default avatar is not being resized and the default avatar is not clickable

any chance of updating the code with different colours for names for males/females?
Title: Re: [Block] Avatar of Users Online
Post by: IchBin on December 01, 2008, 04:56:43 PM
Default avatar size and linking is fixed. How about you take a bit and think about what you want this snippet to do. I can't spend all my time coming back and forth adding features as they come to you. Let me know what you want out of this code so I can do it, and then be done with it. Thanks.

I'm also removing the code that you posted above. I'd like to keep the code posted in the first post to keep the topic cleaned up so users don't get confused when searching in here.
Title: Re: [Block] Avatar of Users Online
Post by: fl4pj4ck on December 01, 2008, 05:42:15 PM
Ok than, sorry for the confusion. I'm trying to transform my TP into some sort of social networking site.

For this module I would like to be able to list all the users that are online or have been within the given time frame.

One module will be located in Upper Panel Block on the frontpage. Ideally I would like it to have just one row and automatically scroll horizontally. If that's too difficult to do - then regular scrollbars will be fine. I would like it to be a little bit more squeezed so I don't waste the space, so just the avatar and the name right under it (both clickable). I would like the colors of the names to represent whether the user is a male or female (blue/pink or maybe use standard icons for gender from SMF).

The second module will be placed on forum itself in the Bottom Panel block (I will create another block for it) to show all users that visited the forum in last 24h. Formatting can be the same, but instead of scrollbars I want to put all the avatars in rows and columns.

that would be it, keep up the good work, thanks for your support

EDIT: instead of names in colors blue/pink could you please add a border around the avatar in that colour and shows the names after hovering the avatar with the mouse (ALT) ???
Title: Re: [Block] Avatar of Users Online
Post by: IchBin on December 01, 2008, 08:23:38 PM
Ok, so this begs the question. What do you do with users who have not selected whether they are a male or female?

Doing all of your requests makes two separate script though really. Having one only show a single row with a marquee scrolling affect isn't something I see the current code doing. So I'll finish the this script first, then change it to do what you need with the scrolling in another topic later.
Title: Re: [Block] Avatar of Users Online
Post by: fl4pj4ck on December 01, 2008, 09:02:23 PM
if they haven't selected we can assume they are all females :) maybe it will make them decide and change it in the profile

this is how it looks right now (avatars 59px, 11 columns):
Title: Re: [Block] Avatar of Users Online
Post by: IchBin on December 01, 2008, 09:16:48 PM
Also, I'm assuming when you say you want their name in the alt attribute, that you're talking about the title so that their name pops up when hovered over? The alt tag is only used if an image is missing.
Title: Re: [Block] Avatar of Users Online
Post by: IchBin on December 01, 2008, 09:32:54 PM
ok, I've edited the code in the first post. I changed some default settings in the configuration so be aware that it may look different until you change the size of things etc.

I added the title to the avatar, as well as the blue (male), pink (female), and default is black if they haven't selected a gender. You can change that if you'd like in the CSS if you want them to be pink by default.

I'll get started on the scrolling block as soon as I finish a few more things here at work. :)
Title: Re: [Block] Avatar of Users Online
Post by: Ken. on December 01, 2008, 09:46:29 PM
Works great IchBinâ,,¢, good job. :up:

Click Me (http://www.ourfamilyforum.org/FamilyForum/index.php?action=forum) and go to the bottom of the page.
Title: Re: [Block] Avatar of Users Online
Post by: IchBin on December 01, 2008, 09:50:55 PM
Looks great Ken! You should adjust your avatar_column td width and height to be closer to the default avatar size you have. This way the text will wrap under the avatar. :) Got the scrolling one done. I think I'll post this in the same topic now that I think about it.
Title: Re: [Block] Avatar of Users Online
Post by: Ken. on December 01, 2008, 09:57:27 PM
Adjusted it a little to make them display larger... looks good from here.

Geesixxie... you needs an avatar.  :o
Title: Re: [Block] Avatar of Users Online
Post by: IchBin on December 01, 2008, 10:16:39 PM
Cool. Text size can be changed if you add it to the CSS. Looks a little small there, but depends on what you like. :) If you read the configuration options a default avatar can be displayed for those who don't have one set. I'll make one up when I get home tonight and attach it to the original post or something.
Title: Re: [Block] Avatar of Users Online
Post by: fl4pj4ck on December 01, 2008, 10:30:54 PM
yup, after few adjustments looks like: click (http://polacywlimerick.com/forum/index.php)

but for some reason there is no border around the default avatar
Title: Re: [Block] Avatar of Users Online
Post by: Ken. on December 01, 2008, 10:33:32 PM
Looks good fl4pj4ck. :)
Title: Re: [Block] Avatar of Users Online
Post by: IchBin on December 01, 2008, 10:34:37 PM
Fixed the code again. Sorry about that, left the class out of the default avatar image code. Should be good to go in the first post again.
Title: Re: [Block] Avatar of Users Online
Post by: ZarPrime on December 01, 2008, 10:45:12 PM
Hi Ichbin,

Very nice block.  Mine is a dark Forum.  This block is all the way at the bottom and looks fantastic ...
http://talesofthehavenexpanse.com/SMF-1/index.php

A couple of questions ...

1.  Is there anything I can change to make the username slightly closer to the bottom of the Avatar?

2.  Is there any way that you would consider adding an option to the configurations to allow the color of the Username's MemberGroup to be used instead of the default color of the theme?  Perhaps the color of the username would default to the theme color unless you change "Use Membergroup Colors" option to "True".

Excellent block.

Thanks for the work,

ZarPrime
Title: Re: [Block] Avatar of Users Online
Post by: fl4pj4ck on December 01, 2008, 10:49:48 PM
looks nice indeed, however it would look nicer if it changes somehow when hovering on top of avatar, can this be done?

and looking forward to have the marquee effect built in :)

thanks IchBinâ,,¢ once again
Title: Re: [Block] Avatar of Users Online
Post by: ZarPrime on December 01, 2008, 11:59:16 PM
Hmmm, I can't seem to change the border color.  For instance, when I try to change ...
      border: 2px solid blue;
to ...
      border: 2px solid lime;
or ...
      border: 2px solid maroon;
or ...
      border: 2px solid green;

... It stays blue.  Anybody else try doing that?

ZarPrime

Title: Re: [Block] Avatar of Users Online
Post by: IchBin on December 02, 2008, 12:03:06 AM
You do a hard refresh? Clear the cache?

Quote from: fl4pj4ck on December 01, 2008, 10:49:48 PM
looks nice indeed, however it would look nicer if it changes somehow when hovering on top of avatar, can this be done?

and looking forward to have the marquee effect built in :)

thanks IchBinâ,,¢ once again

This is exactly why I said you should think about the options you want. So I'm not having to come and work on this code every time you come up with a feature. And when you ask for a feature you need to give detail on what it is EXACTLY that you want. Telling me that it would be nice if it did something on hovering over the avatar doesn't tell me nothing. What do you want? A color change? A size change? details, details, details!!!

The marquee scrolling code is already posted as a second code snippet in the first post of this topic. :)
Title: Re: [Block] Avatar of Users Online
Post by: ZarPrime on December 02, 2008, 12:53:34 AM
Quote from: IchBinâ,,¢ on December 02, 2008, 12:03:06 AM
You do a hard refresh? Clear the cache?

Hi Ichbin,

Not sure if this was for fl4pj4ck or for me, but if it was for me wrt the border colors not changing, the answer is yes, I did a hard refresh.

Thanks for the hard work.

ZP

UPDATE:  OK, I figured out why the border wasn't changing colors and fixed it.  It was because I had set up 2 different blocks with the code, one at the bottom visible to everybody, and one at the top, hidden from everybody except me.  I was working on the top one when it woudn't change.  when I changed the bottom one too, they both changed.  So, it's not a problem after all.
Title: Re: [Block] Avatar of Users Online
Post by: fl4pj4ck on December 02, 2008, 01:30:45 AM
the reason why I came with all the hovering is to have some sort of selection box when the cursor is over the selected avatar.

can you make the avatar zoom a little bit when you put your cursor over it (something light the lightbox effect maybe?)?
if not, then can you make a different colour or thinkness border when the cursor is over the avatar?

I don't like the marquee effect so I'm not going to use it, it looks too sharp when all the avatars are moving. The marquee effect looks ok for text but I belive for pics you need something more sophisticated.
Title: Re: [Block] Avatar of Users Online
Post by: ZarPrime on December 02, 2008, 01:49:38 AM
Hmmm, interesting.  As I said a few messages up, I did 2 blocks.  The first one I did was at the bottom of the page.  The second one was near the top but hidden from everybody except Admins.  I only did this to do some testing on the 2 locations.

If I have the "he" border color in both the top and bottom one set to "lime", the borders are lime.  If I leave the top one set to "lime" but change the bottom one to "maroon" it changes both the top one and the bottom one to maroon.  Interesting phenomenon.

ZP
Title: Re: [Block] Avatar of Users Online
Post by: IchBin on December 02, 2008, 02:19:21 AM
Its called inheritance zarprime. The last rule set in CSS will set all the elements the same as its value. If you want to have two different ones on the same page, just rename the classes in the one code snippet to a different name.

Flapjack, if you want a hover affect just add some more css.

.avatar_column a:hover
{
    border: 4px solid red;
}

You can of course change the border attributes to a different color or size etc.
Title: Re: [Block] Avatar of Users Online
Post by: fl4pj4ck on December 02, 2008, 02:32:07 AM
Quote from: IchBinâ,,¢ on December 02, 2008, 02:19:21 AM
Flapjack, if you want a hover affect just add some more css.

.avatar_column a:hover
{
    border: 4px solid red;
}

You can of course change the border attributes to a different color or size etc.

this is not working, shows a border of about 1/3 size of the avatar in Opera 9.27 a,d FF2
in IE5 it shows the border around the avatar but it has different thickness on left and right side of the avatar

it has to be sth wrong with that code I presume
Title: Re: [Block] Avatar of Users Online
Post by: ZarPrime on December 02, 2008, 02:44:53 AM
Quote from: IchBinâ,,¢ on December 02, 2008, 02:19:21 AM
Its called inheritance zarprime. The last rule set in CSS will set all the elements the same as its value. If you want to have two different ones on the same page, just rename the classes in the one code snippet to a different name.

Hi Ichbin,

Ah, yeah, I knew that.  I't been awhile since I played with CSS and I'm a little rusty on it.  Thanks for refreshing my memory. :up:

I don't want you to spend a lot if time on this since you've already done such an excellent job on this snippet. but, by chance, did you happen to think of a way that I could get the text of the usernames to be the color of the Membergroups that is set in the MemberGroup settings that I mentioned above?

In other words, if a MemberGroup color is set to green the text below their Avatar would display in that color instead of the default color of the theme.

Thanks for your help,

ZarPrime
Title: Re: [Block] Avatar of Users Online
Post by: Ianedres on December 02, 2008, 06:48:26 AM
Good work Ich, throughout it all.  ;)
Title: Re: [Block] Avatar of Users Online
Post by: IchBin on December 03, 2008, 12:10:50 AM
All you need to do is join the membergroup table and grab the membercolor row or whatever its called. If you look at my code you can see how I joined the attachments table. Don't have the time ATM, but I will try to add it when time allows.
Title: Re: [Block] Avatar of Users Online
Post by: Lord Anubis on December 03, 2008, 03:22:22 AM
hey ich, aint tried it yet, but  got some idears for it....my question is does this allow all three types of Avatars

Forum Defaults
User Uploaded
and
URL driven?

If it does, I might integrate this into something, if thats cool with you :)
hell you could even help me out with it I will PM you if you want ;)

BTW: Neat looking script
Title: Re: [Block] Avatar of Users Online
Post by: IchBin on December 03, 2008, 03:47:22 AM
It "should" allow all types of avatars. Whether I did it right is another thing. lol  Feel free to use the code. As for the help you're asking about, only if you get stuck. :) I'm going to try and focus on helping Bloc with some things so I'm not really wanting to take on any more scripts and stuff.
Title: Re: [Block] Avatar of Users Online
Post by: fl4pj4ck on December 03, 2008, 03:14:34 PM
here's the css code if you want nice border when hovering over the avatars:

.avatar_colu/mn
{
bor/der: 4;
}
.avatar_colu/mn a:hover
{
  border: 4px solid #FF0;
}
.avatar_column td
{
height: 60px;
width: 60px;
overflow: hidden;
text-align: center;
vertical-align: top;
}
img.default
{
border: 2px dotted #000;
}
img.he
{
border: 2px dotted #00F;
}
img.she
{
border: 2px dotted #F00;
}

        img.she:hover
{
border: 2px solid #F00;
}
img.default:hover
{
border: 2px solid #000;
}
img.he:hover
{
border: 2px solid #00F;
}


all you need to do is replace the css part from the first post :)

check my website from the sig to see how it works
Title: Re: [Block] Avatar of Users Online
Post by: IchBin on December 03, 2008, 03:19:13 PM
Cool! Glad you figured it out before I did. :) Thanks for sharing!
Title: Re: [Block] Avatar of Users Online
Post by: Lord Anubis on December 03, 2008, 03:30:41 PM
cool Ich will give it a shot :)

thanks
Title: Re: [Block] Avatar of Users Online
Post by: Lord Anubis on December 04, 2008, 02:04:16 AM
Well I am almost there, the last thing that I need is how would I edit the CSS so that the text is as follows:

<div class="smalltext" style="font-family: verdana, arial, sans-serif;">';   :idiot2:

Title: Re: [Block] Avatar of Users Online
Post by: IchBin on December 04, 2008, 04:29:25 AM
You should be able to add the font properties to the avatar_column or avatar_column td class.
Title: Re: [Block] Avatar of Users Online
Post by: cepsi on December 10, 2008, 07:21:06 PM
this is a great little snippet was searching for something similiar to this but this is better than i had hoped to find :D

great job

edit* Not a major thing, but for some reason where my members have no avatar, instead of getting the default avatar (i uploaded an avatar named default_avatar in gif format to my theme as you said) i am getting a 2px by 3px white line of the gender color (ie girls are a pink line, guys blue line and genderless is  default black)
All members with avatars are working fine though :)

i attached a screen shot. Not a big deal but thought i should post. I copied your marquee code from your first post

once again great snippet :D
Title: Re: [Block] Avatar of Users Online
Post by: fl4pj4ck on December 10, 2008, 09:39:10 PM
that can only mean one thing - you provided incorrect path/filename to the default avatar
Title: Re: [Block] Avatar of Users Online
Post by: cepsi on December 10, 2008, 09:47:49 PM
yeah i thought it may be something like that, the path i have to my default avatar  is this;

http://www.my site.com/forum/Themes/dark_4/images/default_avatar.gif

i tried putting into this but im only just starting to learn html and php, so extremely "challenged"

it should go here i guess .. this is what i have done tothis part of the code and obv its not working and help appreciated this is a great snippet may as well get it working properly

<img class="'.$css.'" src="'.$settings['images_url'].'forum/Themes/dark_4/images/default_avatar.gif" width="'.$width.'" height="'.$height.'" alt=""

ty
Title: Re: [Block] Avatar of Users Online
Post by: JPDeni on December 10, 2008, 09:59:16 PM
Try


<img class="'.$css.'" src="'.$settings['images_url'].'default_avatar.gif" width="'.$width.'" height="'.$height.'" alt=""


If that doesn't work, try doing a right-click on the missing image thing and look at the Properties. (Or view the source for your page.) Compare the URL to the image with the URL where you know the image is. There will likely be duplication of some of the code.
Title: Re: [Block] Avatar of Users Online
Post by: IchBin on December 10, 2008, 10:00:15 PM
If you left the code as it was originally, all you have to do is put a default_avatar.gif inside the images directory of any theme you are going to use on your site.

--Deni beat me to it. But yes, that is the code. :)
Title: Re: [Block] Avatar of Users Online
Post by: cepsi on December 10, 2008, 10:12:03 PM
ty guys :) i tried the cliking on the image trick before but the bloody thing was moving too quick cos the line is very small lmao (i also tried the FF webdeveloper  addon but no image was found) Still wont work with the code JP but as long as i know its path related i can concentrate my efforts till i get it right. thanks for the help and the quick replies.
:D

UPDATE i better post this just in case its not me (but likely is ;) this is the code (exactly) as i used it in the block;

global $memberContext, $db_prefix, $scripturl, $modSettings;

/* ###  CONFIGURATION OPTIONS  ### */
// Set time limit using seconds
// 1 hour = 3600
// 1 day = 84600
$timelimit = 84600;

// Set the height and width of avatars
// This will resize the avatars to be more uniform
$width = "40px";
$height = "40px";

// Set or change the style of all the elements
echo '<style type="text/css">
.avatar_column
{
border: 0;
}
.avatar_column td
{
height: 60px;
width: 60px;
overflow: hidden;
text-align: center;
vertical-align: top;
}
.default
{
border: 2px solid black;
}
.he
{
border: 2px solid blue;
}
.she
{
border: 2px solid pink;
}
</style>';

/* ###  END CONFIGURATION OPTIONS  ### */

// Load all users who have logged in within $timelimit
$result = db_query("
SELECT mem.ID_MEMBER, mem.showOnline, mem.lastLogin, mem.realName, mem.avatar, mem.gender, a.ID_ATTACH, a.attachmentType, a.filename
FROM ({$db_prefix}members as mem)
LEFT JOIN {$db_prefix}attachments AS a ON (a.ID_MEMBER = mem.ID_MEMBER)
WHERE mem.lastLogin > (UNIX_TIMESTAMP() - $timelimit)
ORDER BY mem.lastLogin DESC", __FILE__, __LINE__);

$users = array();

// Loop through the results to display the users avatar
while ($row = mysql_fetch_assoc($result))
{
    $users[$row['ID_MEMBER']] = array (
    'id' => $row['ID_MEMBER'],
    'href' => $scripturl.'?action=profile;u='.$row['ID_MEMBER'],
    'name' => $row['realName'],
    'show' => $row['showOnline'],
'gender' => $row['gender'],
    'avatar' => array(
    'image' => $row['avatar'] == '' ? ($row['ID_ATTACH'] > 0 ? 'src="' . (empty($row['attachmentType']) ? $scripturl . '?action=dlattach;attach=' . $row['ID_ATTACH'] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $row['filename']) . '" alt="" border="0" width="'.$width.'" height="'.$height.'" title="'.$row['realName'].'" />' : '') : (stristr($row['avatar'], 'http://') ? 'src="' . $row['avatar'] . '" alt="" border="0" width="'.$width.'" height="'.$height.'" title="'.$row['realName'].'" />' : 'src="' . $modSettings['avatar_url'] . '/' . htmlspecialchars($row['avatar']) . '" alt="" border="0" width="'.$width.'" height="'.$height.'" title="'.$row['realName'].'" />'),
    ),
    );
}

mysql_free_result($result);

echo '
<marquee direction="left">
<table class="avatar_column">
<tr>';

foreach ($users as $user)
{
if ($user['show'] == 1)
{
switch ($user['gender'])
{
case 0:
$css = "default";
break;
case 1:
$css = "he";
break;
case 2:
$css = "she";
break;
}
echo '
<td>',(empty($user['avatar']['image']) ? '<a href="'.$user['href'].'"><img class="'.$css.'" src="'.$settings['images_url'].'default_avatar.gif" width="'.$width.'" height="'.$height.'" alt="" title="'.$user['name'].'" /></a><h6>'.$user['name'].'</h6>' : '<a href="'.$user['href'].'"><img class="'.$css.'" '.$user['avatar']['image'].'</a><h6>'.$user['name'].'</h6>'),'</td>';

}
}

echo '
</tr>
</table>
</marquee>';


I found the image it was showing (the line) and got this returned on a 404

The requested URL /mysmforum/Themes/dark_4/imagesdefault_avatar.gif was not found on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.


i got it working by renaming and uploading  avatar renaming it  "imagesdefault_avatar.gif" lol, horrible shortcut i know but hey! im learning lol
Title: Re: [Block] Avatar of Users Online
Post by: JPDeni on December 11, 2008, 12:04:00 AM
Ah. Well, that explains it. You need a / in there.

Rename the image back to what it should be.

Use


<img class="'.$css.'" src="' . $settings['images_url'] . '/default_avatar.gif" width="' . $width.'" height="'.$height.'" alt=""
[/code[
Title: Re: [Block] Avatar of Users Online
Post by: fl4pj4ck on December 11, 2008, 12:08:40 AM
yup, let's see:
QuoteThe requested URL /mysmforum/Themes/dark_4/imagesdefault_avatar.gif was not found on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

should be:
QuoteThe requested URL /mysmforum/Themes/dark_4/images/default_avatar.gif was not found on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
Title: Re: [Block] Avatar of Users Online
Post by: FERNSIDEâ„¢ on December 11, 2008, 01:10:53 AM
Yeah I was trying to figure out why the first code wasnt showing the default avatar, then I realised the code had   images/default_avatar.gif  when it was already calling from the images folder lol
So    $settings['images_url'].'/default_avatar.gif"    does the job.

I took the quick road and didnt read the thread, sorry if that was pointed out earlier
Title: Re: [Block] Avatar of Users Online
Post by: JPDeni on December 11, 2008, 01:31:51 AM
I'm confused. fl4pj4ck, please copy the error message you're getting. Better yet, give me the URL of the page and I'll look at your page source and figure out what the problem is. Or do you have it fixed now? I'm confused.

Sabreâ,,¢, thanks. :)
Title: Re: [Block] Avatar of Users Online
Post by: fl4pj4ck on December 11, 2008, 01:54:02 AM
sorry for the confusion, I'm not getting the error, just used the error provided to point out what's wrong with the path to the avatar :)
Title: Re: [Block] Avatar of Users Online
Post by: IchBin on December 11, 2008, 02:42:33 AM
Fixed the error in the code. Thanks everyone.
Title: Re: [Block] Avatar of Users Online
Post by: cepsi on December 24, 2008, 04:54:15 PM
an update on this Ich dont know if anyone else is getting it but had a few members complain that when they were logging in they were taken to a blank page with a random avatar and had too go back and sign in again.
i used the process of elimination and took down this snippet (this was 2 weeks ago, been checking everything else b4 posting) and it didnt happen. i put the snippet back up and it started happening again.
i dont know much about these things, but just thought you'd want to know. had to take down this cool snippet cos of this (have alot of complainers on my site lol :(  )
Title: Re: [Block] Avatar of Users Online
Post by: IchBin on December 24, 2008, 05:39:50 PM
Hmm... strange. I don't see why anything in this code would have that affect on your site. Perhaps there is some other block conflicting with this one or something. I haven't seen the error on my site. Would have thought that others would have reported this by now, as I know flapjack is using it. lol
Title: Re: [Block] Avatar of Users Online
Post by: keith021773 on December 24, 2008, 05:48:14 PM
I'm using it on 2 sites and no problems that I know of..  And no one has reported anything.
Title: Re: [Block] Avatar of Users Online
Post by: cepsi on December 24, 2008, 06:12:34 PM
im using alot of blocks so a conflict is right. i love this snippet so will keep chopping and changing to see if i can find out whats causing it
Title: Re: [Block] Avatar of Users Online
Post by: Renegd98 on December 24, 2008, 06:31:07 PM
I use this on 2 sites with no problems, so I am betting your right Ich that there is another block of code conflicting.
Title: Re: [Block] Avatar of Users Online
Post by: contra on December 27, 2008, 10:37:24 PM
Excellent code!

the olny thing i can see it needs is to tell the number of guests online
Title: Re: [Block] Avatar of Users Online
Post by: G6Cad on December 27, 2008, 10:39:25 PM
Quote from: contra on December 27, 2008, 10:37:24 PM
Excellent code!

the olny thing i can see it needs is to tell the number of guests online

The snippet is for show avatars of users online, guests dont have avatars therefor no need to show them eather ;)
Title: Re: [Block] Avatar of Users Online
Post by: contra on December 27, 2008, 10:58:38 PM
yeah, i know, but i was not saying that


i was saying if it show the number of guests it would be great!
Title: Re: [Block] Avatar of Users Online
Post by: IchBin on December 28, 2008, 01:22:32 AM
How would you like to show the number of guests? Details is the only way I can do something if you have an idea as it is not mine. :) I haven't even looked at how guests are logged, so I'm not promising anything lol.
Title: Re: [Block] Avatar of Users Online
Post by: contra on December 28, 2008, 03:28:38 AM
it's cool
Title: Re: [Block] Avatar of Users Online
Post by: Polymath on December 29, 2008, 11:11:58 AM
Is there a speed I can slow it down? Not find it.

Edit. Tis ok..worked out how to control speed.

Nice Thank you all
Title: Re: [Block] Avatar of Users Online
Post by: IchBin on December 29, 2008, 08:07:22 PM
What was the problem with speed? In case others need to know the same thing.
Title: Re: [Block] Avatar of Users Online
Post by: Polymath on December 29, 2008, 09:23:50 PM
Oh yeah, Sorry. I hate that when I read "Don't matter fixed"

It just scrolled to fast for me.

add scrollamount into the marquee code
Find & replace


<marquee direction="left" scrollamount="4">





higher the number the fast it will be.

Title: Re: [Block] Avatar of Users Online
Post by: Polymath on December 29, 2008, 10:24:52 PM
To stop scrolling on mouseover and start up again when moved off:

Find & Replace:

<marquee direction="left" scrollamount="4" onmouseover="this.stop();" onmouseout="this.start();">


Title: Re: [Block] Avatar of Users Online
Post by: IchBin on December 29, 2008, 10:27:28 PM
Ah yes, thanks for that. I planned to add that but had forgotten all about that little feature. :) Thanks!
Title: Re: [Block] Avatar of Users Online
Post by: Polymath on December 29, 2008, 10:35:32 PM
No, Thank you for the block script
Title: Re: [Block] Avatar of Users Online
Post by: Rafferty on January 01, 2009, 12:43:32 AM
Can scroll be added to the column code?
Title: Re: [Block] Avatar of Users Online
Post by: IchBin on January 01, 2009, 08:07:03 PM
It sure can. Just add the marquee code in like its done in the one that's working. Let me know if you need help.
Title: Re: [Block] Avatar of Users Online
Post by: Rafferty on January 01, 2009, 11:18:56 PM
I actually used the second code in a side block, avatars 30x30, and it looks pretty cool scrolling sideways, Thanks Ich.
Title: Re: [Block] Avatar of Users Online
Post by: alving on January 21, 2009, 08:41:52 AM
is it possible to have the avatars centered inside the frame or maybe an option to have it centered or justified to the left..  thanks!  very nice code..
Title: Re: [Block] Avatar of Users Online
Post by: IchBin on January 21, 2009, 02:58:00 PM
You can probably add this to the avatar_column in the css styles at the top of the code.
margin:0 auto;
Title: Re: [Block] Avatar of Users Online
Post by: katers on February 23, 2009, 12:00:24 AM
I am so glad I was directed to this block. 

I looked to see if this was asked and didn't see anything.  Is there a way to make the avatars closer together? 
Title: Re: [Block] Avatar of Users Online
Post by: ZarPrime on February 23, 2009, 01:20:08 AM
Hi twister,

You may have to play with it a little bit, but you control this with the avatar_column td ...
.avatar_column td
{
height: 60px;
width: 60px;
overflow: hidden;
text-align: center;
vertical-align: top;
}


ZarPrime
Title: Re: [Block] Avatar of Users Online
Post by: katers on February 23, 2009, 01:55:36 AM
Thank you I did play around with it and it changed the avatar size, but did nothing for the gap between avatars.  Part of the problem is I can't figure out how to delete the names under the avatars which would afford less of a gap vertically, but not horizontally.
Title: Re: [Block] Avatar of Users Online
Post by: IchBin on February 23, 2009, 02:07:32 AM
Remove <h6>'.$user['name'].'</h6> if you don't want the user names.
Title: Re: [Block] Avatar of Users Online
Post by: UkGangsta on February 24, 2009, 11:16:01 AM
very nice block ichbin works a treat thxs for the super code works flawlessly
Title: Re: [Block] Avatar of Users Online
Post by: fl4pj4ck on February 25, 2009, 01:16:13 PM
one more thing: I recently changed a theme to one with non-fixed sie and wanted to ask if you can modify the code so it wouldn't need to set the fixed number of columns, as they changing on different screens
Title: Re: [Block] Avatar of Users Online
Post by: IchBin on February 25, 2009, 02:14:32 PM
Sorry, but I don't understand what you're asking. Isn't that what the second snippet of code does?
Title: Re: [Block] Avatar of Users Online
Post by: fl4pj4ck on February 25, 2009, 02:23:07 PM
but I would like to see it still in columns/rows and without scrolling effect
Title: Re: [Block] Avatar of Users Online
Post by: IchBin on February 25, 2009, 03:41:59 PM
How does the column/rows change on different screens? If you set them in the options of the code, they cannot change no matter what the screen is doing.
Title: Re: [Block] Avatar of Users Online
Post by: fl4pj4ck on February 25, 2009, 04:57:14 PM
when the resolution is set to 1680x1050 I want to have 20 avatars in a row
when the resolution is set to 1024x768 I want to have 10 avatars, because 20 will simply won't fit in
Title: Re: [Block] Avatar of Users Online
Post by: IchBin on February 25, 2009, 06:39:16 PM
You'd have to use some sort of javascript hack to even get the display. Not something I really want to look into sorry.
Title: Re: [Block] Avatar of Users Online
Post by: Jakki on February 28, 2009, 03:22:34 PM
Just put this on my testing site and works great...love it.
Title: Re: [Block] Avatar of Users Online
Post by: NenaGb on March 16, 2009, 10:32:19 AM
Quote from: contra on December 27, 2008, 10:37:24 PM
Excellent code!

the olny thing i can see it needs is to tell the number of guests online

Not sure if you still need this but you can add this:

$who = ssi_whosOnline('return');
echo 'Total Visitors Online: ', $who['total_users'];


to the end and it will give you total number of visitors to your site. It will count both guests and members.

---


BTW AWESOME CODE! Just what I was looking for!
Title: Re: [Block] Avatar of Users Online
Post by: NenaGb on April 11, 2009, 01:28:03 PM
I have found a new issue with this block code. Its showing user avatars that are no longer on line. Is there a way to keep it in sync with forum's area users online?
Title: Re: [Block] Avatar of Users Online
Post by: Renegd98 on April 11, 2009, 02:29:53 PM
Nena if I remember right this script shows the users on within the last xxx time period.
Title: Re: [Block] Avatar of Users Online
Post by: NenaGb on April 11, 2009, 04:25:27 PM
Any clue how/where to adjust that? The forum area of active users online is set to the admin settings, but this block doesnt follow those same settings.
Title: Re: [Block] Avatar of Users Online
Post by: Renegd98 on April 11, 2009, 04:44:11 PM
If you look at the code the variable $timelimit under Configuration at the top of the code can be adjusted to what you want.
Title: Re: [Block] Avatar of Users Online
Post by: NenaGb on April 11, 2009, 04:57:55 PM
thank you very much :) ;)
Title: Re: [Block] Avatar of Users Online
Post by: katers on April 14, 2009, 10:20:45 PM
Not sure if this is a position problem or code problem, but I placed the second code (scrolling to left) in the lower module position but it does not show on the forum even though the permissions are set and it is activated.  I tried an html code in the lower position and that shows just fine so I am thinking maybe it is because this is a php problem?
Title: Re: [Block] Avatar of Users Online
Post by: ZarPrime on April 14, 2009, 10:51:22 PM
twister,

Have you set the visual options of where to show the block?  Please Read and Reply to the Posting Guidelines (http://www.tinyportal.net/index.php/topic,581) and include a link to your site so that we can see.

ZarPrime
Title: Re: [Block] Avatar of Users Online
Post by: katers on April 15, 2009, 01:54:23 AM
yes permissions are set and as you can see the little banner in the lower panel which is html shows fine, but not the avatars.  www.talkfaux.com
Title: Re: [Block] Avatar of Users Online
Post by: ZarPrime on April 15, 2009, 02:12:19 AM
First of all, did you put the code into a php block?  Secondly, at the bottom on the block creation page (click edit for that block to go there) there is something that says "[Show][Hide]".  Click show and tell me where it says to show the block.

ZarPrime
Title: Re: [Block] Avatar of Users Online
Post by: katers on April 15, 2009, 02:20:15 AM
That was the problem, didn't click the show.  Funny I didn't have to do that for the one that was showing.  Thank you!

Of course now that it is working I see it isn't what I want.  This one scrolls and I want it fixed and to show all in 24 hours like ZarPrime has on her forum.  Ugh!
Title: Re: [Block] Avatar of Users Online
Post by: ZarPrime on April 15, 2009, 06:44:03 AM
twister,

For non-scrolling, use the top code in the first message in the topic instead of the second code ...
http://www.tinyportal.net/index.php/topic,27231.msg216822.html#msg216822

ZarPrime
Title: Re: [Block] Avatar of Users Online
Post by: katers on April 15, 2009, 12:18:48 PM
Thanks, that is what I originally tried to use, but could not figure out how to make it appear in one line.
Title: Re: [Block] Avatar of Users Online
Post by: IchBin on April 15, 2009, 03:12:19 PM
You should be able to set the column for that.
Title: Re: [Block] Avatar of Users Online
Post by: NenaGb on April 21, 2009, 05:35:11 AM
how can i center the avatars in the block?
Title: Re: [Block] Avatar of Users Online
Post by: IchBin on April 21, 2009, 02:58:12 PM
I suppose you could just add align="center" to the table code.
<table class="avatar_column">
Title: Re: [Block] Avatar of Users Online
Post by: fl4pj4ck on March 20, 2010, 08:06:50 PM
there's a missing </td> in the code, spotted it today when working on w3 validation
Title: Re: [Block] Avatar of Users Online
Post by: IchBin on March 22, 2010, 12:56:04 AM
All </td>'s are there that I can see. Maybe if you don't have any users online it may not show any <td>'s.
Title: Re: [Block] Avatar of Users Online
Post by: fl4pj4ck on March 22, 2010, 01:12:14 AM
Quoteif ($counter < $columns)
         {
            echo '
                <td>',empty($user['avatar']['image']) ? '<a href="'.$user['href'].'"><img class="'.$css.'" src="'.$settings['images_url'].'/default_avatar.gif" width="'.$width.'" height="'.$height.'" alt="" title="'.$user['name'].'" /></a><h6>'.$user['name'].'</h6><MISSING /td>' : '<a href="'.$user['href'].'"><img class="'.$css.'" '.$user['avatar']['image'].'</a><h6>'.$user['name'].'</h6></td>';
             $counter++;
         }
         else
         {
            echo '
            </tr>
            <tr>
               <td>',empty($user['avatar']['image']) ? '<a href="'.$user['href'].'"><img class="'.$css.'" src="'.$settings['images_url'].'/default_avatar.gif" width="'.$width.'" height="'.$height.'" alt="" /></a><h6>'.$user['name'].'</h6><MISSING /td>' : '<a href="'.$user['href'].'"><img class="'.$css.'" '.$user['avatar']['image'].'</a><h6>'.$user['name'].'</h6></td>';
            $counter = 1;
         }
Title: Re: [Block] Avatar of Users Online
Post by: IchBin on March 22, 2010, 01:53:01 AM
Ah yes, in the middle of the turnary statement.... Didn't see that one. lol I meant to do it like the second snippet where the </td> wasn't included in the statement.
Title: Re: [Block] Avatar of Users Online
Post by: Lord Anubis on June 07, 2011, 01:03:12 AM
Did some modifying to the block...

(https://www.tinyportal.net/proxy.php?request=http%3A%2F%2Fwww.blabbster.com%2Fcrap%2Fusers.png&hash=0260d34e0a8941c89a6ec082c0e197f3e97ab1ac)

Finally got it the way I wanted, great code Ich  O0