×
Kunena 6.0.5 Released - Security release (21 Nov 2022)

The Kunena team has announce the arrival of Kunena 6.0.5 [K 6.0.5] which is now available for download as a native Joomla extension for J! 4.2.x. This version addresses most of the issues that were discovered in K 6.0 and issues discovered during the development stages of K 6.0. This is a security release.

× This category for technical discussions among experienced, skilled developers who either want to integrate own their software with Kunena or who are developing new features for Kunena.

Please introduce yourself and your goals before asking the questions.

Please do not ask questions about when new versions of Kunena will be released. They will not be answered here and may result in locking the topic from further discussion.

Idea Integrating avatars between Kunena and your component

More
10 years 5 months ago - 10 years 5 months ago #1 by Matias
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:
<?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):
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:
// 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:
// 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:
// 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.
Last edit: 10 years 5 months ago by Matias.
The following user(s) said Thank You: NicholasJohn16

Please Log in or Create an account to join the conversation.

More
10 years 4 months ago #2 by NicholasJohn16
Awesome example, Matias.

Please Log in or Create an account to join the conversation.

More
10 years 2 months ago #3 by deathbrigner
Is there a way to do something like this but with a url... I'd like to preset my avatars by username... so AE: www.exemple.com/skins/{username}.png ?

Please Log in or Create an account to join the conversation.

More
9 years 11 months ago #4 by nefsan
woooowww and SUPER WOOOOOWWWWW. You save me man. i just spend many hours looking for this response. Is the only one on the net. Thanks.

My problem was i wanted to integrate k2 and kunena avatars. So just delete the code in k2 that loads default avatar and replace it for the code of kunena avatar. Now k2 uses kunena avatar.


Really thanks, :woohoo: :silly: :lol: :cheer: :)

Please Log in or Create an account to join the conversation.

  • Not Allowed: to create new topic.
  • Not Allowed: to reply.
  • Not Allowed: to edit your message.
Time to create page: 0.126 seconds