1
Xtracted
Display username and avatar in a block?
  • 2004/7/1 11:41

  • Xtracted

  • Not too shy to talk

  • Posts: 138

  • Since: 2004/1/7 2


I need to add some users username and avatars to a block and I want it to look just like the "most active members" or "new members" block.. This should be pretty simple huh? =)

2
Xtracted
Re: Display username and avatar in a block?
  • 2004/7/2 10:23

  • Xtracted

  • Not too shy to talk

  • Posts: 138

  • Since: 2004/1/7 2


Oh, c'mon...

3
Xtracted
Re: Display username and avatar in a block?
  • 2004/7/2 12:39

  • Xtracted

  • Not too shy to talk

  • Posts: 138

  • Since: 2004/1/7 2


Ok, I figured out how to call the username with html code..

<a href="http://www.pagename.com/userinfo.php?uid=idnumber here">

Avatar seems a bit harder.. I can of course just add a link to the avatar, but if the user changes avatar you would have to update the block manually...

How can I call for a users avatar with html?

4
ian-m
Re: Display username and avatar in a block?
  • 2004/7/2 14:17

  • ian-m

  • Just popping in

  • Posts: 7

  • Since: 2004/6/29


I'm working on this as well. It most likely can't be done with just html, but if you put in some php to query your database you should be able to pull out the path. I haven't put this into action on my server yet, but here's an idea using what you've got:
// first you want the username, so that's what you had above:

echo "<a href='http://www.pagename.com/userinfo.php?uid=idnumber'>";

// next you need to connect to the database with your xoops
// user (or any user with select privileges on the XOOPS db

// obviously replace with real values
$db mysql_connect('localhost''your_xoops_user''your_pass'); 

// again replace with real value
mysql_select_db('your_xoops_db'$db);

// form your sql query
$query "SELECT user_avatar FROM xoops_users WHERE uid=some_number";

// ask
$answer mysql_query($query$db);

// if there's an error you should make some kind of default
if(!$answer){
  echo 
"<img src='default.jpg'>";
}

// I'm planning on fetching multiple data, so I wrote it
// this way, you could probably do it some other way though

$array mysql_fetch_array($answer);

// this is different depending on how and where you've
// stored the avatars, by default avatars are stored in your
// http://yourxoopssite.com/uploads/

echo "<img src='http://yourxoopssite.com/uploads/".$array['user_avatar']."'>";


That should do it, but again, I haven't put this in place yet myself (and I'm relatively new to php/mysql).

Hope this helps, good luck!

5
sottwell
Re: Display username and avatar in a block?
  • 2004/7/2 15:01

  • sottwell

  • Just popping in

  • Posts: 30

  • Since: 2004/6/23


I do believe that you can get the user's avatar from the $xoopsUser object.

from the Xoops wiki

$xoopsUser->getVar('uname') - gets the username
$xoopsUser->getVar('uid') - gets the user id

I think you might be able to use:

$xoopsUser->getVar('user_avatar')

At least that's what it's called in the database.

6
ian-m
Re: Display username and avatar in a block?
  • 2004/7/2 15:40

  • ian-m

  • Just popping in

  • Posts: 7

  • Since: 2004/6/29


Well, now that I've had more time to actually give my code a shot, I see that it doesn't work because of a fairly obvious html mistake that I managed to miss (I intended to create a link with the avatar image, but I left out echo "</a>"; at the end. Oops.)

Though, now I have a strange problem I don't understand.

When I put "echo $xoopsUser->getVar('uname');" I get a blank page in a block, regardless if anything else is in the block, I get "Fatal error: Call to a member function on a non-object in /home/(removed)/public_html/class/xoopsblock.php(146) : eval()'d code on line 1"

Do I need to modify xoopsblock.php to include some function to get at these variables? The wiki refers to modules, but this is just a simple block, so that would be my guess, but I don't know where to start on that. Thanks for any help.

7
sottwell
Re: Display username and avatar in a block?
  • 2004/7/2 16:57

  • sottwell

  • Just popping in

  • Posts: 30

  • Since: 2004/6/23


I don't think you can just code in a block like that. It has to be a module, with blocks. You're not getting all of the system initialization including loading of globals like $xoopsUser. You can try including mainfile.php, that might do the trick.

8
sottwell
Re: Display username and avatar in a block?
  • 2004/7/2 18:00

  • sottwell

  • Just popping in

  • Posts: 30

  • Since: 2004/6/23


I found something you might want to look at:

Who's Online Hack Site

Go to downloads/modules, and you'll find it listed as "exibegrupos.zip".

It's just a function that you copy into your code and call as needed. It's in Portugese/Brasilian, I believe, but the code itself is pretty clear, and should give you the general idea of what you want.

9
ian-m
Re: Display username and avatar in a block?
  • 2004/7/2 22:19

  • ian-m

  • Just popping in

  • Posts: 7

  • Since: 2004/6/29


Ah, I wasn't clear on what could and could not be done. I assumed this would be a fairly common thing to do. I'll take a look at this later on, thanks for the pointers.

Login

Who's Online

197 user(s) are online (119 user(s) are browsing Support Forums)


Members: 0


Guests: 197


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Mar 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits