Using CjBlog avatars in your custom component

Prerequisites

$api = JPATH_ROOT.'/components/com_cjblog/api.php';
if(file_exists($api))
{
  include_once $api;
  //rest of integration code here
}

Prefetching Users

If you are loading multiple user avatars at a time, it is good idea to pre-fetch all such user profiles at once which will save some DB calls and thereby improves performance.
Pre-fetching CjBlog user profiles

Loading Single User Avatar

If you are loading an avatar of a single user, you can use the following code to load the avatar. This will output the user avatar linked to the profile of the CjBlog user profile.

echo CjBlogApi::get_user_avatar($userid, $height, $displayname, $attribs, $img_attribs);
  • $userid – number – ID of the user
  • $height – number – optional – Image height. Recommended values are 16, 32, 48, 64, 96, 128, 160, 192, 256. default is 48
  • $displayname – string – optional – valid values are name and username. default is name
  • $attribs – array – optional – an associative array of attributes for the user profile link. ex: array(‘class’=>’thumbnail’)
  • $img_attribs – array – optional – an associative array of attributes for the image. ex. array(‘title’=>’Test User’)

Loading Multiple User Avatars

If you are loading multiple user avatars, for example on a listing page, loading all user avatars at a time will reduces number of calls to the database and increase performance. You can simply pass an array of user ids to the avatar API as if you are loading single user avatar.

$avatars = CjBlogApi::get_user_avatar($userids, $height, $displayname, $attribs, $img_attribs);
  • $userids is an array of user ids.
  • Rrturns – An associative array with index as user id and value as user avatar linked with CjBlog user profile.

Developers Video Tutorials



Search the website