Avatar sharing
egomac - April 27, 2007 - 07:48
| Project: | SMFforum Integration module |
| Version: | 5.x-1.x-dev |
| Component: | User interface |
| Category: | support request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
Jump to:
Description
Just want to ask if SMF forum integration can share the same avatar for both drupal and the forums? Thanks.

#1
In current version avatars is not synced. No plans when i could start to do this.
#2
I got avatar sharing working in one direction on my localhost test box. .. Drupal profile to SMF forum Profile...
The code below updates the SMF "I have my own pic:" profile field with a link to your drupal user's avatar.
It works well in "SMF master" mode but if you have your module set to "Drupal Master" then it updates the SMF avatar field every time you log in. It still works in drupal master mode but its probably not a good thing for site performance?.. The code is pretty much a copy of the routine before it...and I am also not familiar enough with the way the modes work in this module to fix it for drupal master.
Here is the code..it starts on line 1153(right after the signature update rountine) in the latest version of smfforum-5.x-1.0 (from the demo site http://vgb.org.ru/). Keep in mind You will also have to set your site address in $siteprefx.
if (SMF_SYNC_TO_DRUPAL|| count($edit) != 0) {if ($op == 'update' && $sync == SMF_SYNC_TO_SMF)
$val = $edit['picture'];
else
$val = $account->picture;
$valsmf = smf_api_utf8($smf_user_info['avatar']);
// You must set your site path in $siteprefx below.
// Enter drupals home before the path where drupal stores user pictures.
// e.g. 'http://localhost/example/' comes before "files/avatars/Examplepic.png"
$siteprefx = 'http://localhost/example/';
if ($val != $valsmf) {
if ($sync == SMF_SYNC_TO_SMF)
$data += array('avatar' => '\'' . $siteprefx . smf_api_charset($val) .'\'');
}
}
So far I have tested it with registering new drupal members and logging in with a few existing ones and the drupal avatar syncs to the smf forum profile just fine. For my site I aiming for my smf profile links to be re-directed to drupal's profile page at all times(with htaccess redirects?) so I don't plan on having anyone using the SMF profile configuration at all. I am still not sure what the difference is with drupal master or SMF master mode in this setup but the module seems to have no problems syncing the drupal profile edits and new drupal user registrations to smf accounts in smf master mode.
Also.. Keep in mind I am using the drupal log in box and not the smf log in blocks that can be enabled with this module...again.. I figured I might need it to be the other way around if its in "smf master" mode but I am having no problems logging in to drupal and being automatically logged in to smf with the existing drupal log in box.
#3
Thanks for idea and code.
I have tested.
To SMF it works. To Drupal needs additional coding. I will see.
Instead of $siteprefx better to use global $base_url;
global $base_url;$data += array('avatar' => '\'' . $base_url . "/" . smf_api_charset($val) .'\'');#4
No problem.. Thank you for a great module!... And thanks for the global $base_url; suggestion. I wish I could help you with the "to drupal" syncing from smf but that is way beyond my current php skills.
#5
I had a problem with the drupal guestbook module and that avatar code. When the guestbook book page opens to the current users personal guest book page... it seems that it calls up part of the users edit screen..which sets blank values to $val & $valsmf causing a blank avatar sync to smf from drupal.
Here is a workaround..this adds a check to see if the user is on his/her own guestbook page.
if (SMF_SYNC_TO_DRUPAL || count($edit) != 0) {if ($op == 'update' && $sync == SMF_SYNC_TO_SMF)
$val = $val = $edit['picture'];
else
$val = $account->picture;
$valsmf = smf_api_utf8($smf_user_info['avatar']);
global $base_url;
global $user;
$uid = $user->uid;
$fs_refer= $_SERVER ['REQUEST_URI'];
$fs_refer = explode("guestbook/" , $fs_refer);
$guestbsafe = $fs_refer[1];
if ($val != $valsmf) {
if ($uid != $guestbsafe && $sync == SMF_SYNC_TO_SMF)
$data += array('avatar' => '\'' . $base_url . "/" . smf_api_charset($val) .'\'');
}
}
I also think I figured out why drupal master keeps injecting the avatar values every time you log in. $val & $valsmf are never the same value unlike the rest of the fields (signature etc.)but luckily if your updating only your drupal avatar profile in smf master mode then the avatar code is only called when you need it.
#6
I just found another problem with my code.. If you update the signature in the drupal profile then it injects an empty field into the smf user avatar setting ...unless your editing them at the same time. The other fields dont have a problem with this..just the sig. Here is a fix for it. BTW I also moved the guestbook check up to the if statement that it was under.
if (SMF_SYNC_TO_DRUPAL || count($edit) != 0) {
if ($op == 'update' && $sync == SMF_SYNC_TO_SMF)
$val = $edit['picture'];
else
$val = $account->picture;
$valsmf = smf_api_utf8($smf_user_info['avatar']);
global $base_url;
global $user;
$uid = $user->uid;
$fs_refer= $_SERVER ['REQUEST_URI'];
$fs_refer = explode("guestbook/" , $fs_refer);
$guestbsafe = $fs_refer[1];
if ($uid != $guestbsafe && $val != $valsmf) {
if ($val != NULL && $sync == SMF_SYNC_TO_SMF)
$data += array('avatar' => '\'' . $base_url . "/" . smf_api_charset($val) .'\'');
}
}
I also checked the signature field in the SMFforum Integration module latest version against the drupal guestbook module. ( http://drupal.org/project/guestbook ) Sure enough..the same thing happens with the blank fields. Here is a fix for that.
if (SMF_SYNC_TO_DRUPAL || count($edit) != 0) {if ($op == 'update' && $sync == SMF_SYNC_TO_SMF)
$val = $edit['signature'];
else
$val = $account->signature;
$valsmf = smf_api_utf8($smf_user_info['signature']);
global $base_url;
global $user;
$uid = $user->uid;
$fs_refer= $_SERVER ['REQUEST_URI'];
$fs_refer = explode("guestbook/" , $fs_refer);
$guestbsafe = $fs_refer[1];
if ($uid != $guestbsafe && $val != $valsmf) {
if ($sync == SMF_SYNC_TO_SMF)
$data += array('signature' => '\'' . smf_api_charset($val) .'\''); //smf_api_charset($val)
else
$data += array('signature' => $valsmf);
}
}
#7
I spoke to soon about the other fields.... I thought I tested the custom profile fields but I found another snag when working with the guest book module. I am using the mapped website url field to send the users website to smf so it will show it in the smf member list page. I changed the custom profile field return @ around line 1025 to fix the same blank fields problem.
$var = variable_get('smfforum_map_websiteUrl', 'profile_websiteUrl');$val = $account->{$var};
$valsmf = smf_api_utf8($smf_user_info['websiteUrl']);
if ($val != $valsmf) {
if ($val != NULL && $sync == SMF_SYNC_TO_SMF) // added $val != NULL to the argument
$data += array('websiteUrl' => '\'' . smf_api_charset($val) .'\'');
elseif (!empty($valsmf))
$data += array($var => $valsmf);
}
After I did that I realized I could clean up the original sig and avatar guestbook check with
$val != NULLSignature Updater
if (SMF_SYNC_TO_DRUPAL || count($edit) != 0) {if ($op == 'update' && $sync == SMF_SYNC_TO_SMF)
$val = $edit['signature'];
else
$val = $account->signature;
$valsmf = smf_api_utf8($smf_user_info['signature']);
if ($val != $valsmf) {
if ($val != NULL && $sync == SMF_SYNC_TO_SMF)
$data += array('signature' => '\'' . smf_api_charset($val) .'\'');
elseif (!empty($val))
$data += array('signature' => $valsmf);
}
}
Avatar Updater
if (SMF_SYNC_TO_DRUPAL || count($edit) != 0) {if ($op == 'update' && $sync == SMF_SYNC_TO_SMF)
$val = $edit['picture'];
else
$val = $account->picture;
$valsmf = smf_api_utf8($smf_user_info['avatar']);
global $base_url;
if ($val != $valsmf) {
if ($val != NULL && $sync == SMF_SYNC_TO_SMF)
$data += array('avatar' => '\'' . $base_url . "/" . smf_api_charset($val) .'\'');
}
}
#8
Done.
You can download and test updated version from site Drupal+SMF
Drupal 5 module smfforum.module (updated smf_api_2 already included) smfforum-5.x-1.0-dev.tar.gz
#9
Just got a chance to test out the new module going from drupal to smf. The avatar sync works for me but my setup has a few issues. The first one is... When I upload an avatar picture in drupal I see a message above the normal smf sync messages... it says " ! The selected file could not be copied". The avatar still syncs just fine but I still see that message. I wonder if that has to do with the way my smf forum is setup? I tried relaxing the avatar permissions a bit in smf but I still get that message. Perhaps I need to specify a specific folder in the "Upload avatars to..." section of smf. I'll give that try in a bit...
I am also seeing a smf avatar sync update message whenever I log in with the normal drupal log in. That happens when I set the module to "Drupal Master" mode. When I set is back to SMF master the login update message goes away just like in the old version.
Last problem... I am having the same blank fields problem with the guestbook module ( http://drupal.org/project/guestbook ). When I click the link to my profile's guestbook..a null value for my avatar (probably $val = $edit['picture'] ) is injected in to my smf profile. I can see the smf avatar sync message there as well.
#10
Fixed guestbook
See http://vgb.org.ru/node/21
You can download and test updated version from support site.
About drupal copy message The selected file could not be copied
Check directories and their permissions. See and check SMF avatar settings
#11
Just tested your latest code and it works great! No more Guestbook problems. Thanks again VB! I will mess around with my smf directory stuff to get rid of the copy message.