[HOW TO] Add avatar to pages

How-to's, little tricks, tutorials, code examples (snippets) and read-me's.

[HOW TO] Add avatar to pages

Postby harmlessgoat22 » 11 Apr 2007, 11:40

To show the avatar of the currently logged in user, follow these steps.

Open includes/functions.php

Find (around line 3880):
Code: Select all
    // Which timezone?
    
$tz = ($user->data['user_id'] != ANONYMOUS) ? strval(doubleval($user->data['user_timezone'])) : strval(doubleval($config['board_timezone']));


After, add:
Code: Select all
    // Adding Avatar Variable
    
    
$avatar_img '';

    if (
$user->data['user_avatar'])
        {
            switch (
$user->data['user_avatar_type'])
            {
                case 
AVATAR_UPLOAD:
                
$avatar_img $phpbb_root_path $config['avatar_path'] . '/';
                break;
        
                case 
AVATAR_GALLERY:
                
$avatar_img $phpbb_root_path $config['avatar_gallery_path'] . '/';
                break;
            }
            
$avatar_img .= $user->data['user_avatar'];
    
            
$avatar_img '<img src="' $avatar_img '" width="' $user->data['user_avatar_width'] . '" height="' $user->data['user_avatar_height'] . '" alt="" />';
    }


Next, find (should be pretty close to where you already are):
Code: Select all
'LAST_VISIT_DATE'                => sprintf($user->lang['YOU_LAST_VISIT'], $s_last_visit),


After it, add:
Code: Select all
'AVATAR'                        => $avatar_img,




It's that simple. And to add it to a template, just type in {AVATAR} and it will show up. However, it is suggested that you use
Code: Select all
<!-- IF S_USER_LOGGED_IN -->{AVATAR}<!-- ENDIF -->

because users not logged in will not have an avatar.
User avatar
harmlessgoat22    
STG Support Team
STG Support Team
 
Posts: 2886
Joined: 13 Jul 2006, 17:38
Gender: Male
phpBB Knowledge: 8




phpBB Academy at StarTrekGuide
Support STG
Using PayPal Donate

Re: [HOW TO] Add avatar to pages

Postby Highway of Life » 11 Apr 2007, 17:03

I think this code should be a function... I found it was used 7 times in 8 files.
Bug submitted with DIFF file included.
We?ll see what they do... I?ve submitted this before.
Watch out! I might do a code wheelie!

User avatar
Highway of Life    
STG Jedi Master
STG Jedi Master
 
Posts: 10458
Joined: 08 May 2006, 05:23
Location: Beware of Programmers carrying screwdrivers
Gender: Male
phpBB Knowledge: 10

Re: [HOW TO] Add avatar to pages

Postby 3Di » 30 Apr 2008, 09:43

Should be updated this KB article, I guess. Correct me if I'm wrong, that's completely possible.
Give Peace A Chance.. Pass ON It!
Image
The door that leads to the Glory is very narrow but it is mandatory to be Great to be able to cross it.
------------------------- phpBB wiki in Italiano - partecipa con il tuo contributo -----------------------
User avatar
3Di    
MOD Author
MOD Author
 
Posts: 249
Joined: 22 Apr 2008, 14:09
Location: Italy
Favorite Team: Milan
Gender: Male
phpBB Knowledge: 8

Re: [HOW TO] Add avatar to pages

Postby jaunty_mellifluous » 02 Sep 2008, 08:42

I used that code on my site. It shows avatars that are linked off site but doesn't show any avatars that are uploaded onto my servers. Any ideas why?
http://forum.roadsout.com
jaunty_mellifluous
Crewman
Crewman
 
Posts: 2
Joined: 02 Sep 2008, 08:40
Gender: Male

Re: [HOW TO] Add avatar to pages

Postby Highway of Life » 07 Sep 2008, 00:59

get_user_avatar() is the new function to use... the code shown on the first page is obsolete. :)
Watch out! I might do a code wheelie!

User avatar
Highway of Life    
STG Jedi Master
STG Jedi Master
 
Posts: 10458
Joined: 08 May 2006, 05:23
Location: Beware of Programmers carrying screwdrivers
Gender: Male
phpBB Knowledge: 10

Re: [HOW TO] Add avatar to pages

Postby jaunty_mellifluous » 07 Sep 2008, 01:21

Could you explain to me a little about how to use get_user_avatar()? All I have to do is place it to the place where I want the avatar to be displayed? I want to display it in the overallheader.html somewhere.
jaunty_mellifluous
Crewman
Crewman
 
Posts: 2
Joined: 02 Sep 2008, 08:40
Gender: Male

Re: [HOW TO] Add avatar to pages

Postby harmlessgoat22 » 07 Sep 2008, 06:48

Code: Select all
$template->assign_vars(array(
   'USER_AVATAR'            => get_user_avatar($user->data['user_avatar'], $user->data['user_avatar_type'], $user->data['user_avatar_width'], $user->data['user_avatar_height']),
));

That's the code for defining a template variable as the current logged in user's avatar.
User avatar
harmlessgoat22    
STG Support Team
STG Support Team
 
Posts: 2886
Joined: 13 Jul 2006, 17:38
Gender: Male
phpBB Knowledge: 8

Re: [HOW TO] Add avatar to pages

Postby topdown » 24 Sep 2008, 01:34

I just noticed an issue with the function get_user_avatar
you can't use it in the header without including
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
in the ucp.php otherwise it is undefined.
Do not PM me for Support unless I give permission in a post......PM's only help one, posts help everyone !
User avatar
topdown    
STG Styles Leader
STG Styles Leader
 
Posts: 3027
Joined: 01 Oct 2007, 22:56
Location: Handyman's harddrive
Favorite Team: STG Teams
Gender: Male
phpBB Knowledge: 9

Re: [HOW TO] Add avatar to pages

Postby Flick » 01 Mar 2009, 08:01

Okay I'm confused now, lol - it doesn't take much to do to be honest! lol
So the code in the first post no longer works, so what do I have to do to get this to work?

Edit: My appologise, I don't know what I was doing wrong. Just reinstalled the backup files and started again, and lo-and-behold its working. Great code, thank you very much!
Flick    
Cadet II
Cadet II
 
Posts: 22
Joined: 04 Aug 2008, 11:56
Location: Liverpool, UK
Favorite Team: The LSU Team
Gender: Male
phpBB Knowledge: 3

Re: [HOW TO] Add avatar to pages

Postby Flick » 14 Mar 2009, 21:09

Okay sorry for the double post, but this is sort of the old problem and not.
The code works perfectly everywhere but /blog.php (which will soon be the index page) I'm using this custom page to port my wordpress blog into phpbb3. The page works perfectly in phpbb3 before the user_avatar was added to my sidebar in phpbb3.

However now I get this error "Fatal error: Call to undefined function get_user_avatar() in /home/.dharma/breezeest/schola-draiochta.com/includes/functions.php on line 3753"

I've tried adding "include($phpbb_root_path . 'includes/functions_display.' . $phpEx);" into the wordpress functions.php but when I do I get the following error
Spoiler:
[phpBB Debug] PHP Notice: in file /wp-united/wp-functions.php on line 33: include(includes/functions_display.) [function.include]: failed to open stream: No such file or directory
[phpBB Debug] PHP Notice: in file /wp-united/wp-functions.php on line 33: include() [function.include]: Failed opening 'includes/functions_display.' for inclusion (include_path='.:/usr/local/php5/lib/php:/usr/local/lib/php')

Fatal error: Call to undefined function get_user_avatar() in /home/.dharma/breezeest/schola-draiochta.com/includes/functions.php on line 3753


I'm assuming it's becuase I'm trying to use "$phpbb_root_path ." and haven't defined what that path is. I'm not sure how to define the phpbb3 path in wordpress. If it helps any my phpbb3 board is located in the root and wordpress is located in cms/wordpress but its also tied in with /wp-united/

Edit: I've just found that I' also get the following error when I goto the PM's section of the UCP.
Fatal error: Cannot redeclare display_forums() (previously declared in /home/.dharma/breezeest/schola-draiochta.com/includes/functions_display.php:22) in /home/.dharma/breezeest/schola-draiochta.com/includes/functions_display.php on line 537 :rolleyes:
Flick    
Cadet II
Cadet II
 
Posts: 22
Joined: 04 Aug 2008, 11:56
Location: Liverpool, UK
Favorite Team: The LSU Team
Gender: Male
phpBB Knowledge: 3

Next

Return to Tutorials and How-Tos

Who is online

Users browsing this forum: Google [Bot] and 9 guests