Support Forum

Trying to call Simplepress profile and avatar into a CBox chat box

35 Answers

New Answer

NA Nate
Nate
Member

Isn’t $user_id the get user WordPress call? http://codex.wordpress.org/WPMU_Functions/get_current_user_id

CBox is totally separate from WordPress but CBox recently made it so that you can integrate the CBox chat box with your WordPress users. Before integration, guests and members of my site had to pick a username for the chat box and then post their message in the chat box, but now the integration allows members already logged in to my site to post messages on the chat box.

What I’m trying to do is get the usernames INSIDE the chat box (which are the same usernames of my WordPress members) to link to their SimplePress profiles and show their SimplePress avatars. It’s the exact same username as they use on my forums because the cbox is pulling them from my WordPress database.

Well avatars sorta work now all of a sudden…I just posted a message in the chat box and it shows my avatar http://www.rockitpro.com/testimonies/ but it’s not showing the member’s avatar below me. He should have the standard avatar showing. My Sho-Down name is also linking to http://www.rockitpro.com/sf-forum/ instead of my profile.

The code you gave me is having no effect though, CBox is pulling my avatar with &pic=<?php echo urlencode($avatar_url)?>

MP Mr Papa
Mr Papa
Member

well first, that function is not getting called… just $user_ID being used…  and that gets back to the CURRENT logged in user…  when you want to show those avatars in the chat, you want the user id of that user, NOT the current logged in user…  so the chat box has to be providing the user id…  or giving us a prototype such that we can insert a url with a placeholder for the user id…

as I said, I have not idea where $user_ID and $user_identity are coming from in the code snippet you have…  which is why I asked if cbox was filling it for each user in the chat window where you want an avatar and profile link…

I can give you the url prototype, but I cannot create the IDs for the users in the chat box…  but they must know how to do it…

NA Nate
Nate
Member

Check the image I posted above, the $user_ID and $user_identity are in Step 1 on my CBox integration set up page where it tells me to post this into my theme:

<?php global $user_ID, $user_identity ?> <?php if ( $user_ID ) : ?> [your Cbox HTML code] <?php endif; ?>
NA Nate
Nate
Member

So this is the original CBox code that I have on http://www.rockitpro.com/testimonies/ right now, it’s pulling my avatar and linking my username to http://www.rockitpro.com/sf-forum/

<?php global $user_ID, $user_identity ?>
<!-- BEGIN CBOX - www.cbox.ws - v001 -->
<div id="cboxdiv" style="text-align: center; line-height: 0">
<ul><li>
<div><i.f.r.ame frameborder="0" width="286" height="185" src="http://www5.cbox.ws/box/?boxid=377963&boxtag=6685&sec=main" scrolling="auto" allowtransparency="yes" name="cboxmain5-377963" style="border:#DBE2ED 0px solid;" id="cboxmain5-377963"></iframe></div>
<div><i.f.r.ame frameborder="0" width="286" height="75" src="http://www5.cbox.ws/box/?boxid=377963&boxtag=6685&sec=form&nme=<?php echo urlencode($user_identity)?>&nmekey=<?php echo md5('privatekey'.$user_identity)?>&pic=<?php echo urlencode($avatar_url)?>&lnk=<?php echo urlencode($profile_url)?>&ekey=<?php echo md5("privatekey"."t".$avatar_url."t".$profile_url)?>" scrolling="no" allowtransparency="yes" name="cboxform5-377963" style="border:#DBE2ED 0px solid;border-top:0px" id="cboxform5-377963"></iframe>
</li></ul>
</div></div>
<!-- END CBOX -->
MP Mr Papa
Mr Papa
Member

you are missing my point… where is $user_ID actually getting a value??  is it filled by cbox??? 

what form do they want for $avatar_url and $profile_url??? 

each of those urls are based on the specific user that you want see them for…  at this point in the code, we do not know the user id of each user you are going to show an avatar for…

I can of course give the prototype or form of the urls but I cannot fill the data at this point…  its likely they are using placeholders for the data – would just need to know the format…  and it they want a user id for the profile, we dont use that… its user_login not the id…

this may seem complex, but in the world of APIs, its quite straight forward… just have to know the details of both sides (ie expected inputs and outputs)..

NA Nate
Nate
Member

Yea man, I’m totally lost lol. I’ll pass along the info to the cbox admin and see what he says

NA Nate
Nate
Member

Here’s what he said:

I’m glad to see that your own profile/avatar linking is working — this suggests the code is fine, but that the other users are not configured with avatars, or something else is getting in the way. It sounds like you are getting good support from the platform provider. This information may be useful:

Cbox only requires three variables from the platform, which it inserts into the iframe source query string:

$user_identity — this is just the current user’s display name, a UTF-8 string.
$profile_url — this is an absolute URI for the current user’s profile page, a string as above.
$avatar_url — this is an absolute URI for the current user’s picture, a string as above. This URI needs to end in a supported image format extension, e.g. .gif, .jpg, or .png.

Your Integration code does the urlencoding necessary on these strings, so they just need to be available (in scope) at the point that your Integrated Cbox code is inserted.

The names of these variables are not important; only their position in the Integrated Cbox code matters.

But as mentioned, the fact that your own avatar/profile is working suggests the Integrated code is already okay, and that there’s some other problem preventing other users’ details being brought into scope — perhaps a platform setting is preventing other user groups’ info from being retrieved from the database or session?

NA Nate
Nate
Member

And here’s the code that shows my avatar, so something’s on the right track, it’s just not showing other member’s avatars or the correct profile url:

<?php 
 global $user_ID, $user_identity; 
 sp_forum_api_support();
 $user_login = get_user_meta($user_ID, 'user_login', true);
 $profile_url = sp_url().urlencode($user_login);
 $avatar = sp_UserAvatar('get=1&context=user', $user_ID);
 $avatar_url = $avatar->url;
 ?>
<!-- BEGIN CBOX - www.cbox.ws - v001 -->
<div id="cboxdiv" style="text-align:center; line-height:0">
<ul><li>
<i.f.rame frameborder="0" width="286" height="185" src="http://www5.cbox.ws/box/?boxid=377963&boxtag=6685&sec=main" scrolling="auto" allowtransparency="yes" name="cboxmain" style="border:#DBE2ED 0px solid;" id="cboxmain"></iframe>
<i.f.rame frameborder="0" width="286" height="75" src="http://www5.cbox.ws/box/?boxid=377963&boxtag=6685&sec=form&nme=<?php echo urlencode($user_identity)?>&nmekey=<?php echo md5('PRIVATEKEY'.$user_identity)?>&pic=<?php echo urlencode($avatar_url)?>&lnk=<?php echo urlencode($profile_url)?>&ekey=<?php echo md5("PRIVATEKEY"."t".$avatar_url."t".$profile_url)?>" scrolling="no" allowtransparency="yes" name="cboxform" style="border:#DBE2ED 0px solid;border-top:0px" id="cboxform"></iframe>
</li></ul>
</div></div>
<!-- END CBOX -->
MP Mr Papa
Mr Papa
Member

good that these guys are staying with you here…

but they are right, if its working for you, it should be working for them…

have any other users posted a chat since you put the above code in place??? it cannot go back in time and create the profile and avatar urls.  But when a user make a new chat entry, it should get them…

NA Nate
Nate
Member

Avatars are working. I just created a new user, uploaded an avatar and posted a message www.rockitpro.com and it’s showing the avatar.

Now we just need to figure out why the username is linking to http://www.rockitpro.com/sf-forum/ instead of http://www.rockitpro.com/sf-forum/profile/usernamehere

NA Nate
Nate
Member

Also, shouldn’t this work: $avatar = sp_UserAvatar(‘get=1&width=20px&context=user’, $user_ID);

I’m trying to resize the avatar from 45 to 20px but it’s still coming up 45×45

Edit: Nevermind, avatar size is controlled by CBox css, got sizes changed.

MP Mr Papa
Mr Papa
Member

on avatar size, okay… but the argument in our template function is size, not width…

if it worked for you and worked for their avatar, should for profile too…

looking more at the cbox code, since they already do a urlencode(), I would change:

$profile_url = sp_url().urlencode($user_login);

to

$profile_url = sp_url().$user_login;

but not likely to matter…  what is the login name of this account?

NA Nate
Nate
Member

Yea that didn’t change anything, still linking to http://www.rockitpro.com/sf-forum/

Log in name of which account?

MP Mr Papa
Mr Papa
Member

the user account you created and tested with…  but I think I see the issue… lets try this instead – think I was over complicating it… just the part before the cbox stuff…

<?php 
 global $user_ID, $user_identity, $user_login; 
 sp_forum_api_support();
 $profile_url = sp_url().$user_login;
 $avatar = sp_UserAvatar('get=1&context=user', $user_ID);
 $avatar_url = $avatar->url;
 ?>