Topic-icon User avatars and username position

Active Subscriptions:

None
13 years 1 month ago #32523 by Bettychung
OK Alex, I will try another one or ask the developer.
BTW, could you please provide me the code to get the user avatars and and the user name? And can it include the feature link to user profile by clicking the avatars and username?

Thank you!
The topic has been locked.
Support Specialist
13 years 1 month ago #32536 by alzander
The code for getting a user avatar from Facebook, and link to that profile on Facebook, is:
$user = JFactory::getUser();
$jUserId = $user->get('id');
$userMapModel = new JFBConnectModelUserMap(); 
$fbUserId = $userMapModel->getFacebookUserId($jUserId);
$profileLibrary = JFBConnectProfileLibrary::getInstance(); 
$fbAvatarUrl = $profileLibrary->getAvatarUrl($userMapModel->getFacebookUserId($jUserId); 
# Show their FB avatar (if desired), or give them the option to link accounts 
$fbProfileUrl = 'https://www.facebook.com/profile.php?id='.$fbUserId;
if ($fbAvatarUrl) 
       echo 'Welcome '.$user->get('name').'<a href="' . $fbProfileUrl .'"><img src="' . $fbAvatarUrl . '" /></a>';
Hope that helps,
Alex
The topic has been locked.
Active Subscriptions:

None
13 years 1 month ago #32542 by Bettychung
Hi Alex, Thank you for your help.
And I am so sorry about my bad PHP knowledge. I am tried to copy the code you provided to Flexi Custom Content module, but it just display the code not the username and avatars at FrontPage.
So I am wondering if I need to add some additional code before the one you provided, such as add a "<div class" like you provide before
<div class="username">Hello <?php echo JFactory::getUser()->get('username'); ?></div>

Thank you!
The topic has been locked.
Support Specialist
13 years 1 month ago #32546 by alzander
Sorry, yes, you'll need to use the <?php tags, like:
<?php
$user = JFactory::getUser(); 
$jUserId = $user->get('id'); 
$userMapModel = new JFBConnectModelUserMap(); 
$fbUserId = $userMapModel->getFacebookUserId($jUserId); 
$profileLibrary = JFBConnectProfileLibrary::getInstance(); 
$fbAvatarUrl = $profileLibrary->getAvatarUrl($userMapModel->getFacebookUserId($jUserId); 
# Show their FB avatar (if desired), or give them the option to link accounts 
$fbProfileUrl = 'https://www.facebook.com/profile.php?id='.$fbUserId; 
if ($fbAvatarUrl) 
       echo 'Welcome '.$user->get('name').'<a href="' . $fbProfileUrl .'"><img src="' . $fbAvatarUrl . '" /></a>';
?>
<div class="my_style">Outside of the PHP tags, you can insert normal HTML</div>
Hope that helps, but if you need anything else, let me know.

Thanks,
Alex
The topic has been locked.
Active Subscriptions:

None
13 years 1 month ago #32652 by Bettychung
Hi Alex, with no luck, the code still not work.
Can I just copy the code to the custom code module?
I pasted this code
<?php 
$user = JFactory::getUser(); 
$jUserId = $user->get('id'); 
$userMapModel = new JFBConnectModelUserMap(); 
$fbUserId = $userMapModel->getFacebookUserId($jUserId); 
$profileLibrary = JFBConnectProfileLibrary::getInstance(); 
$fbAvatarUrl = $profileLibrary->getAvatarUrl($userMapModel->getFacebookUserId($jUserId); 
# Show their FB avatar (if desired), or give them the option to link accounts 
$fbProfileUrl = 'https://www.facebook.com/profile.php?id='.$fbUserId; 
if ($fbAvatarUrl) 
       echo 'Welcome '.$user->get('name').'<a href="' . $fbProfileUrl .'"><img src="' . $fbAvatarUrl . '" /></a>';
?>
to the custom code module. And then I can't open my site. Errors like this:
Strict Standards: Only variables should be assigned by reference in /modules/mod_flexi_customcode/tmpl/default.php on line 24

Strict Standards: Non-static method modFlexiCustomCode::parsePHPviaFile() should not be called statically in /modules/mod_flexi_customcode/tmpl/default.php on line 54

Parse error: syntax error, unexpected ';' in /tmp/htmlOw8tdZ on line 7
I am keeping doing this many times but not works. If possible and if you have time to check it at my backend? :)
Thank you!
The topic has been locked.
Support Specialist
13 years 1 month ago #32661 by alzander
It should be able to be pasted in, but there was a typo in my code above. There is a missing ) at the end of the line that starts with $fbAvatarUrl =.

The corrected code is:
$user = JFactory::getUser();
    $jUserId = $user->get('id');
    $userMapModel = new JFBConnectModelUserMap();
    $fbUserId = $userMapModel->getFacebookUserId($jUserId);
    $profileLibrary = JFBConnectProfileLibrary::getInstance();
    $fbAvatarUrl = $profileLibrary->getAvatarUrl($userMapModel->getFacebookUserId($jUserId));
    # Show their FB avatar (if desired), or give them the option to link accounts
    $fbProfileUrl = 'https://www.facebook.com/profile.php?id='.$fbUserId;
    if ($fbAvatarUrl)
           echo 'Welcome '.$user->get('name').'<a href="' . $fbProfileUrl .'"><img src="' . $fbAvatarUrl . '" /></a>';
In that, there are 2 )) at the end of that line, which is correct.

Very sorry for the confusion. Please try that and let us know how it goes.

Thanks,
Alex
The topic has been locked.
Active Subscriptions:

None
13 years 1 month ago #32897 by Bettychung
Hi Alex, I am very appreciated your help on this issue. But with no luck, I tried this many times and I still can't make it, and the code seems not work either. Could you help me at my backend to check it? If you have time to help me I will send you the access info. via PM.

Thanks in advance!
Mark
The topic has been locked.
Support Specialist
13 years 1 month ago #32907 by alzander
Mark,
Sure, please do Private Message me and we'll take a look over the next few days. When you PM me, please make sure to describe what module to edit, where we should see the results, and as much other information as you can provide so we know exactly what we're looking for.

Thanks,
Alex
The topic has been locked.