Difference between revisions of "Using CjForum user avatars in your component"

From CjWiki
Jump to navigation Jump to search
 
Line 2: Line 2:
 
== Prerequisites: ==
 
== Prerequisites: ==
 
Add the required CjForum API library:
 
Add the required CjForum API library:
<syntaxhighlight lang="php">require_once JPATH_ROOT.'/components/com_cjforum/lib/api.php';</syntaxhighlight>
+
<pre>require_once JPATH_ROOT.'/components/com_cjforum/lib/api.php';</pre>
  
 
Now get the profile API:
 
Now get the profile API:
<syntaxhighlight lang="php">$profileApi = CjForumApi::getProfileApi();</syntaxhighlight>
+
<pre>$profileApi = CjForumApi::getProfileApi();</pre>
  
 
== Syntax: getUserAvatar ==
 
== Syntax: getUserAvatar ==
 
Syntax of the getUserAvatar API call to get full HTML image tag linked to CjForum profile page of the user:
 
Syntax of the getUserAvatar API call to get full HTML image tag linked to CjForum profile page of the user:
<syntaxhighlight lang="php">getUserAvatar($identifiers, $size = 48, $username = 'name', array $attribs = array(), array $image_attribs = array())</syntaxhighlight>
+
<pre>getUserAvatar($identifiers, $size = 48, $username = 'name', array $attribs = array(), array $image_attribs = array())</pre>
  
 
; $identifiers - int/array or ints:
 
; $identifiers - int/array or ints:
Line 25: Line 25:
  
 
Get avatar of the user with full html markup, linked to user profile page.
 
Get avatar of the user with full html markup, linked to user profile page.
<syntaxhighlight lang="php">$avatarLink = $profileApi->getUserAvatar($userId, 48, 'username');</syntaxhighlight>
+
<pre>$avatarLink = $profileApi->getUserAvatar($userId, 48, 'username');</pre>
  
 
Get avatar of the user with full html markup, linked to user profile page, with user's original name as display name:
 
Get avatar of the user with full html markup, linked to user profile page, with user's original name as display name:
<syntaxhighlight lang="php">$avatarLink = $profileApi->getUserAvatar($userId, 64, 'name');</syntaxhighlight>
+
<pre>$avatarLink = $profileApi->getUserAvatar($userId, 64, 'name');</pre>
  
 
Get user avatar with some attributes to the html link and image of the markup produced by function call:
 
Get user avatar with some attributes to the html link and image of the markup produced by function call:
<syntaxhighlight lang="php">$avatarLink = $profileApi->getUserAvatar($userId, 48, 'name', array('class'=>'avatarlink'), array('class'=>'avatar', 'style'=>'border: 1px solid #ccc'));</syntaxhighlight>
+
<pre>$avatarLink = $profileApi->getUserAvatar($userId, 48, 'name', array('class'=>'avatarlink'), array('class'=>'avatar', 'style'=>'border: 1px solid #ccc'));</pre>
  
 
== Syntax: getUserAvatarImage ==
 
== Syntax: getUserAvatarImage ==
 
Syntax of the getUserAvatarImage API call to get location of the user avatar image:
 
Syntax of the getUserAvatarImage API call to get location of the user avatar image:
<syntaxhighlight lang="php">getUserAvatarImage($identifiers, $size = 48, $force_reload = false)</syntaxhighlight>
+
<pre>getUserAvatarImage($identifiers, $size = 48, $force_reload = false)</pre>
  
 
; $identifiers - int/array or ints:
 
; $identifiers - int/array or ints:
Line 47: Line 47:
  
 
Get location of the user avatar with size 48 pixels.
 
Get location of the user avatar with size 48 pixels.
<syntaxhighlight lang="php">$url = $profileApi->getUserAvatarImage($userId, 48);</syntaxhighlight>
+
<pre>$url = $profileApi->getUserAvatarImage($userId, 48);</pre>
  
 
Get avatar images of set of users:
 
Get avatar images of set of users:
<syntaxhighlight lang="php">$url = $profileApi->getUserAvatarImage($userIds, 64);</syntaxhighlight>
+
<pre>$url = $profileApi->getUserAvatarImage($userIds, 64);</pre>

Latest revision as of 03:54, 8 August 2019

Prerequisites:

Add the required CjForum API library:

require_once JPATH_ROOT.'/components/com_cjforum/lib/api.php';

Now get the profile API:

$profileApi = CjForumApi::getProfileApi();

Syntax: getUserAvatar

Syntax of the getUserAvatar API call to get full HTML image tag linked to CjForum profile page of the user:

getUserAvatar($identifiers, $size = 48, $username = 'name', array $attribs = array(), array $image_attribs = array())
$identifiers - int/array or ints
Single user id or array of user ids for which the user avatars need to be fetched. If array of user ids given, the function will return associative array of user profile urls/links with user id as key. Required parameter.
$size - int
Size of the avatar image in pixels. Default 48, optional parameter.
$username - string
Type of user name to be used as alt text. Possible values are name and username. Default: name. Optional parameter.
$attribs - array
Associative array of key value pairs used for building HTML link attributes. Default: array(). Optional parameter.
$image_attribs - array
Associative array of key value pairs used for building HTML image attributes. Default: array(). Optional parameter.

Examples:

Get avatar of the user with full html markup, linked to user profile page.

$avatarLink = $profileApi->getUserAvatar($userId, 48, 'username');

Get avatar of the user with full html markup, linked to user profile page, with user's original name as display name:

$avatarLink = $profileApi->getUserAvatar($userId, 64, 'name');

Get user avatar with some attributes to the html link and image of the markup produced by function call:

$avatarLink = $profileApi->getUserAvatar($userId, 48, 'name', array('class'=>'avatarlink'), array('class'=>'avatar', 'style'=>'border: 1px solid #ccc'));

Syntax: getUserAvatarImage

Syntax of the getUserAvatarImage API call to get location of the user avatar image:

getUserAvatarImage($identifiers, $size = 48, $force_reload = false)
$identifiers - int/array or ints
Single user id or array of user ids for which the user avatar images need to be fetched. If array of user ids given, the function will return associative array of user profile urls/links with user id as key. Required parameter.
$size - int
Size of the avatar image in pixels. Default 48, optional parameter.
$force_reload - boolean
if true, the user avatar name will be fetched from database even if it exists in cache. Optional parameter.

Examples:

Get location of the user avatar with size 48 pixels.

$url = $profileApi->getUserAvatarImage($userId, 48);

Get avatar images of set of users:

$url = $profileApi->getUserAvatarImage($userIds, 64);