(How to...) Add user avatar to the sidebar with Mys v1.3.3

Forum
Last Post
Threads / Messages

Hall of Famer

Administrator
Staff member
Administrator
Joined
Dec 15, 2008
Messages
4,564
Points
48
Location
United States
Mysidian Dollar
214,223
Well this is a simple tutorial for admins to add user avatar as a module to their users, it assumes that you uses Mys v1.3.3. For earlier versions you may have to do this by editing script files, which can be a problem.

So to begin with, go to module manager in your ACP, create a new module with basic information as entered below:
Y8dXxdU.png


It does not matter what name you give to your avatar module, but the required userlevel can be tricky. Enter 'member' as suggested above, otherwise it may attempt to get avatars for guests and return an error message.

The next thing to do is to enter the module's PHP code. The PHP code is evaluated by the script's internal code, but there are a few variables you may need to keep track of. One of them is $mysidia, which stores important system information. The other is $moduleContainer, which serves as container for your GUI module. Sounds complicated? Well for this tutorial you do not need to know how they work, since I will provide the actual code to get this avatar module done for you. However, you may want to learn a bit more about them if you plan to add some custom php code completely yourself.

Anyway, in the field 'module php code' text area, enter the following code below:

PHP:
$profile = $mysidia->user->getprofile();
$avatar = new Image($profile->getAvatar());
$avatar->resize(200);
$moduleContainer->add($avatar);
And we are all done, submit the form and your users will find their avatar displayed on the sidebar. You can change the value '200' in $avatar->resize(200) to get any size you want for your site, 200 is used here since the width of default sidebar column is about that size. Your user may have a problem if they have rectangular shaped avatar rather than squarely shaped, but this cant be helped. The avatar module in action is shown below:

NWpPwPI.png

This concludes my tutorial for how to add user avatars to your site, lemme know if you encounter any issues. Also you can change the display order for each sidebar module in ACP too, just in case you havent noticed yet. Have fun playing with the script, everyone.
 
Last edited:
*Dances* Wonderful! I was just wondering about this too :D

Thanks, HoF ^_^
 
What error are you getting? Did it say that it cannot find the class 'Image'?
I think I have seen that error message before when trying to install other stuff, but with this specific avatar module installation, it has no errors, but also isn't showing any avatar in the sidebar, it's just blank.
 

Attachments

  • 1647123222989.png
    1647123222989.png
    677.3 KB · Views: 5
This code will work for Mys v1.3.6:

PHP:
use Resource\Core\Registry;
use Resource\GUI\Component\Image;
$mysidia = Registry::get("mysidia");
$profile = $mysidia->user->getprofile();
$avatar = new Image($profile->getAvatar());
$avatar->resize(200);
$moduleContainer->add($avatar);

Also updated the first post since the images on tinypic.com were no longer available.
 
This code will work for Mys v1.3.6:

PHP:
use Resource\Core\Registry;
use Resource\GUI\Component\Image;
$mysidia = Registry::get("mysidia");
$profile = $mysidia->user->getprofile();
$avatar = new Image($profile->getAvatar());
$avatar->resize(200);
$moduleContainer->add($avatar);

Also updated the first post since the images on tinypic.com were no longer available.
Thank you! Much appreciated.
 

Similar threads

Users who are viewing this thread

  • Forum Contains New Posts
  • Forum Contains No New Posts

Forum statistics

Threads
4,274
Messages
33,115
Members
1,602
Latest member
BerrieMilk
BETA

Latest Threads

Latest Posts

Top