Using CjBlog profile system

From CjWiki
Jump to: navigation, search

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 profiles 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

Get User Profile Link

If you are displaying multiple user profile links on a page, prefetch the users before or load all user profile links as shown below. The same call can be used to fetch single user profile link when userid passed as an integer value.

$links = CjBlogApi::get_user_profile_url($userids, $displayname, $path_only, $attribs, $xhtml, $ssl);
  • $userids - mixed - user ids of one or more users. If numeric id of single user is passed, the API will return user profile link of that user. If array of multiple user ids is passerd, the API will return associative array of user profile links indexed on user id.
  • $displayname - string - optional - valid values are name and username
  • $path_only - boolean - optional - tells if API needs to load the URL of the user profile or full HTML markup of the user profile link.
  • $attribs - array - optional - an associative array of HTML hyperlink attributes (name, value pairs)
  • $xhtml - boolean - optional - tells if API needs to load xhtml valid link
  • $ssl - boolean - optional - to load secure link

Get just the user profile image

Sometimes, you want to integrate the CjBlog user avatar but not the user profile. In such cases, this function will help you get the user profile image instead of full hyperlinked image.

$image = get_user_avatar_image($identifiers, $size, $force_reload);
  • $identifiers - mixed - numeric value of user id in case single user needs to be loaded, array of ids otherwise. The output is single user avatar image in case numeric id is passed, otherwise returns associative array of user avatar images indexed on user id.
  • $size - number - optional - size of the image to be loaded. Recommended values are 16, 32, 48, 64, 96, 128, 160, 192, 256. default is 48.
  • $force_reload - boolean - optional - loads the user from database even if the user is already loaded. default is false.

Getting user profile

Get the full user profile.

$profile = CjBlogApi::get_user_profile($user_ids, $force);
  • $user_ids - integer or array of integers - user ids
  • $force - optional - forces the system to load profile from database even if it is already loaded. default is false.