Use your avatars in Kunena
To integrate your avatars into Kunena, you need to create a small plugin. Easiest example how to do it can be found from
here
. For more examples, please see our existing integrations in
here
.
This is how the main plugin file looks like:
Code:
<?php
defined ( '_JEXEC' ) or die ();
class plgKunenaYourComponent extends JPlugin {
public function __construct(&$subject, $config) {
// Do not load if Kunena version is not supported or Kunena is not installed
if (!(class_exists('KunenaForum') && KunenaForum::isCompatible('2.0') && KunenaForum::installed())) return;
// TODO: Here you should detect your component and return if detection fails!
parent::__construct ( $subject, $config );
$this->loadLanguage ( 'plg_kunena_kunena.sys', JPATH_ADMINISTRATOR );
$this->path = dirname ( __FILE__ ) . '/kunena';
}
/*
* Get YourComponent avatar integration object.
*
* @return YourComponentAvatar
*/
public function onKunenaGetAvatar() {
if (!$this->params->get('avatar', 1)) return;
require_once "{$this->path}/avatar.php";
return new KunenaAvatarYourComponent($this->params);
}
}
In the constructor you just need to add detection for your own component, so that plugin doesn't cause any fatal errors if your component isn't installed.
Once you have done that, you just need to implement your own logic to grab your avatar images into avatar.php file (example in
here
).
To avoid having too many queries in Kunena pages, you should also implement a function that loads all users at once (put into KunenaAvatarYourComponent class):
Code:
public function load($userlist)
{
YourFactory::loadUsers($userlist);
}
Use Kunena avatars in your component
On the other hand, to get Kunena avatar into your component, you need to start by detecting if Kunena can be found:
Code:
// Detect and initialize Kunena (only needed to do once)
if (!(class_exists('KunenaForum') && KunenaForum::isCompatible('2.0') && KunenaForum::installed())) return false;
KunenaForum::setup();
return true;
If you want to fetch data from more than one user, you should start by pre-loading all the users you need:
Code:
// BTW: you don't have to put returned users into variable, but sometimes it's useful to have the list
$users = KunenaForumUserHelper::loadUsers(array(63,64,65,66,67,68));
And here is the actual code (with 3 variations depending on what you need) to use Kunena avatars in your component:
Code:
// Initialize variables
$sizex = $sizey = 90;
$class = 'avatar';
$user = KunenaFactory::getUser();
// Get avatar URL "/media/kunena/avatars/path/file.jpg"
$avatarUrl = $user->getAvatarURL($sizex, $sizey);
// Get avatar <img> tag
$avatarHtml = $user->getAvatarImage($class, $sizex, $sizey);
// Get profile link with avatar pointing to profile page
$userLink = $user->getLink(null, $avatarHtml);
Please note that if Kunena is integrating to another component, avatars and profile page may be pointing to that another component. For example if Kunena uses Gravatars, your component will do the same.