Creating Custom Avatar Engine

Discussion forum for MOD Writers regarding MOD Development.
Locked
bashbang
Registered User
Posts: 8
Joined: Sun Sep 16, 2007 9:25 pm

Creating Custom Avatar Engine

Post by bashbang » Thu Oct 04, 2007 2:57 am

I'm in the process of porting over a flash custom avatar engine I built to work in VBulletin but am a bit stuck with the integration of it into phpBB 3.x. I'm hoping someone can point me in the right direction.

The flash part is all independant of phpBB...even the page that the user uses to customize the avatar is seperate from the board. I'm having troubles getting it to work properly in the postbit.

I've added the following to constants.php:
define('AVATAR_CUSTOM', 4);

then in functions_display.php I have this:
case AVATAR_CUSTOM:
return ' {fill in flash object stuff here}'
break;

Now when I go to the board (haveing previously chosen a standard avatar from the library) I switch it to use my custom avatar. This does the flash magic in my costum tables in the database and also updates the phpbb_users table with this:
UPDATE phpbb_users SET user_avatar_type = 4 WHERE user_id = $user->data['user_id'];

I'm sorta stumped as to why it's not changing. I figure there's an additional setting or option that needs to be switched. Can anyone point me in the right direction?

Thanx

User avatar
A_Jelly_Doughnut
Former Team Member
Posts: 34457
Joined: Sat Jan 18, 2003 1:26 am
Location: Where the Rivers Run
Contact:

Re: Creating Custom Avatar Engine

Post by A_Jelly_Doughnut » Thu Oct 04, 2007 3:55 am

The solution depends on your problem. If, for example, you have no avatar displaying, I would suspect that the get_user_avatar() function returning (for example) a blank string. View the HTML source, and see if your flash HTML is showing up where it should.
A Donut's Blog
"Bach's Prelude (Cello Suite No. 1) is driving Indiana country roads in Autumn" - Ann Kish

bashbang
Registered User
Posts: 8
Joined: Sun Sep 16, 2007 9:25 pm

Re: Creating Custom Avatar Engine

Post by bashbang » Thu Oct 04, 2007 5:48 am

A_Jelly_Doughnut wrote:The solution depends on your problem. If, for example, you have no avatar displaying, I would suspect that the get_user_avatar() function returning (for example) a blank string. View the HTML source, and see if your flash HTML is showing up where it should.
If I use the UCP to remove the library avatar then choose my Flash avatar (setting phpbb_users.user_avatar_type = 4) nothing is displayed.

If I use a library avatar and try to override it with the flash avatar it still displays the library avatar. So no, the flash object is not rendering in the HTML at all.

User avatar
A_Jelly_Doughnut
Former Team Member
Posts: 34457
Joined: Sat Jan 18, 2003 1:26 am
Location: Where the Rivers Run
Contact:

Re: Creating Custom Avatar Engine

Post by A_Jelly_Doughnut » Thu Oct 04, 2007 1:40 pm

That implies that your code in ucp_avatar.php is broken. That is where the avatar is changed in the database. Get_user_avatar only looks there and pushes it out to the user.
A Donut's Blog
"Bach's Prelude (Cello Suite No. 1) is driving Indiana country roads in Autumn" - Ann Kish

bashbang
Registered User
Posts: 8
Joined: Sun Sep 16, 2007 9:25 pm

Re: Creating Custom Avatar Engine

Post by bashbang » Thu Oct 04, 2007 4:05 pm

A_Jelly_Doughnut wrote:That implies that your code in ucp_avatar.php is broken. That is where the avatar is changed in the database. Get_user_avatar only looks there and pushes it out to the user.
indeed, you are correct. I forgot a piece of the puzzle. I modified the get_user_avatar function to have a optional paramater passed in called $poster_id like so:

Code: Select all

function get_user_avatar($avatar, $avatar_type, $avatar_width, $avatar_height, $alt = 'USER_AVATAR', $poster_id=0)
in the includes/functions_display.php. This var is passed into the flash movie so the flash movie knows how to build the avatar.

I've also updated the viewtopic.php file like so:

Code: Select all

'avatar'                => ($user->optionget('viewavatars')) ? get_user_avatar($row['user_avatar'], $row['user_avatar_type'], $row['user_avatar_width'], $row['user_avatar_height'], 'User Avatar', $poster_id) : '',
on line 1020 where $user_cache[$poster_id] = array is being defined.

I do see that get_user_avatar is being used in other places like:
includes/acp/acp_groups.php
includes/acp/acp_users.php
includes/mcp/mcp_notes.php
includes/mcp/mcp_warn.php
includes/ucp/ucp_groups.php
includes/ucp/ucp_pm_viewmessage.php
includes/ucp/ucp_profile.php
memberlist.php

and I'll get to those once I can get it working in the viewtopic area. Saying all that, it's still not working. Any other insights? Or even perhaps a better method of attacking the integration of this mod?

User avatar
Brf
Support Team Member
Support Team Member
Posts: 51868
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}
Contact:

Re: Creating Custom Avatar Engine

Post by Brf » Thu Oct 04, 2007 4:12 pm

Did you remember to clear your board's cache after changing those files?

bashbang
Registered User
Posts: 8
Joined: Sun Sep 16, 2007 9:25 pm

Re: Creating Custom Avatar Engine

Post by bashbang » Thu Oct 04, 2007 4:23 pm

Brf wrote:Did you remember to clear your board's cache after changing those files?
Yes...several times now. :) Make a change, clear the browser cache, clear the board cache...see if it worked, rinse, repeat...

bashbang
Registered User
Posts: 8
Joined: Sun Sep 16, 2007 9:25 pm

Re: Creating Custom Avatar Engine

Post by bashbang » Thu Oct 04, 2007 4:45 pm

ok, so I know I'm missing something. In viewtopic.php, just before

Code: Select all

$user_cache[$poster_id] = array(
I did a
die(print_r($row));
to see what the contents of the row are as I see it's being used here:

Code: Select all

'avatar'		=> ($user->optionget('viewavatars')) ? get_user_avatar($row['user_avatar'], $row['user_avatar_type'], $row['user_avatar_width'], $row['user_avatar_height'], 'User Avatar', $poster_id) : '',
and I get the full array dumped to screen but the result of the avatar vars are so:

[user_avatar] => [user_avatar_type] => 0

Looking at the mysql table I see this
+-------------+------------------+
| user_avatar | user_avatar_type |
+-------------+------------------+
| | 4 |

now if I look at the get_user_avatar function I know it's gona return a blank avatar because of this initial test:

Code: Select all

	if (empty($avatar) || !$avatar_type)
	{
		return '';
	}
I'm cool with that...I get it. NP, I can resolve that. What I don't get is on a different user I data dump of this
[user_avatar] => 10.jpg [user_avatar_type] => 4

and it still doesn't work...but I don't see why that's the case.

bashbang
Registered User
Posts: 8
Joined: Sun Sep 16, 2007 9:25 pm

Re: Creating Custom Avatar Engine

Post by bashbang » Fri Oct 05, 2007 5:13 pm

OK, figured it out. Posting for the record and to help others who happen to google this posting.

It turned out to be two problems. One stupid human error (that being me), the other was a diag error (again that was me but was due to the first stupid error).

1) I have two forums installed on the same database and was looking at the wrong phpbb_users table. oops!

2) Once I discoverd that error (and it still wasn't working) I looked at the functions_display.php file once more and addressed the fact that it was testing for a blank $avatar var which forced it to ignore the switch statement. I made the change of just updating the phpb_users.user_avatar field to a custom holding image location (like so: /avatar/custom_avatar.gif") at the same time I set the phpb_users.user_avatar_type=4.

This prefents the "blank" avatar field test from passing and proceeding to the switch where my avatar_type field is then found and the obj code rendered.

Now to update the function call in those other files and I'm gold.

Thank you for you help A_Jelly_Doughnut and Brf

bashbang
Registered User
Posts: 8
Joined: Sun Sep 16, 2007 9:25 pm

Re: Creating Custom Avatar Engine

Post by bashbang » Sat Oct 06, 2007 2:07 am

In case anyone wants to see the flash avatars in action: http://toonbarn.com/forum/viewtopic.php?f=82&t=148

Locked

Return to “[3.0.x] MOD Writers Discussion”