If your component show user names somewhere it is essential for 100% integration with Touch to preprocess user name before render. Touch will add to the name drop down menu which will be accessible on click or on moseover on the name. It will add online status and VIP status. Or even statuses that was granted by one user to another.
By implementing this technique you get your application totally Touched and user will have the same look & feel all over the site where Touch and your component are inatelled.
Here is the code example:
$API = JPATH_ROOT.DS.'components'.DS.'com_community'.DS.'api.php'; if(file_exists($API)) { require_once $API; $user_name = JSCommunityApi::getUserSlideMenu($user_id, $user_name, $links, $params); }
This is the most simple code example.
First I’ll explain all the parameters and then I’ll show you an example of how you can implement it more technically.
- $user_id – is an ID of the user whose name you want to add dropdown menu to.
- $user_name – the name of the user. It may be user name or user login name. (probably will be depreciated in future version to centralize user names type.)
- $links – Array of additional links to add to dropdown menu,
- $params – Params how dropdown menu should looks like
look here is the some nice stuff $links. You may add some additional links to dropdown menu. Dropdown menu shows links that are assigned by community integration plugins. There may be links of different components. There is separate article on how to add permanent link to user menu. Read it here. Permanent means that this link will be shown on all pages of the site in user drop down menu.
But sometimes it is useful to have some links that relate only to this current page and not have to be there permanently. Like for example here http://www.mightyextensions.com/whats-going-on if you get dropdown of any user you will see there 2 links. Those are User Activity History and User Groups Activity history. Those link are just a filter of current page to show activity only user or only groups user joined. They reload current page with new parameters. You will not see those links in dropdown menu anywhere on the site.
Or another example here http://www.mightyextensions.com/download-3dp-components/list/3dp-extensions/resources/80-fields. If you see dropdown of any user you will see “All user extensions (5)” that will lead you on the list of all extensions added by current user. You see that there is no purpose to show this link in activity stream and links that is in activity stream to show on this page.
So if you have those links you may add it to dropdown menu. Here is example of what you how you can add links:
$links = array(); $links[0]->link = JRoute::_('index.php?option=com_resource&view=list&category_id='.$category->id. '&Itemid='.JRequest::getInt('Itemid').'&user_id='.$user->get('id')); $links[0]->alt = JText::_('Show all records by this user'); $links[0]->icon = 'components/com_resource/images/user_record.png';
You may add as many elements to array as possible. But of course keep reasoning not to add to many.
For example if you integrate forum you may want to add links to write PM through you forum PM system. See all user posts or user statistic if you not show it in Touch profile through integration plugin.
Params variable is an optional parameter and allows you to apply some formatting changes to dropdown menu.
Here is the list of possible parameters.
$params['avatar_width'] = 60; $params['avatar_height'] = 60; $params['width'] = 350; $params['slide_mode'] = 'vertical'; $params['pos_mode'] = 'bottom'; $params['avatar'] = true;
Default values are changed in Touch global configuration, that is why I do not recommend you to set any parameters there. Just skip this parameter.
Let me show you more practical way of integrating using this knowledge.
function convertName($user_id, $user_name) { Static $capi = false; Static $api_enabled = true; if($api_enabled == false) return $user_name; if(!$capi) { $API = JPATH_ROOT.DS.'components'.DS.'com_community'.DS.'api.php'; if(file_exists($API)) { require_once $API; $capi = new JSCommunityApi(); } else { $api_enabled = false; return $user_name; } } $params['width'] = 400; $links[0]->link = JRoute::_('index.php?option=com_my&view=list&Itemid='. JRequest::getInt('Itemid').'&user_id='.$user_id); $links[0]->alt = JText::_('Show all records by this user'); $links[0]->icon = 'components/com_my/images/user_record.png'; $user_name = $capi->getUserSlideMenu($user_id, $user_name, $links, $params); return $user_name; } echo convertName($id, $name);
Function like this will give you few advantages.
- Links you add to menu and parameters you keep in one place
- It will check for API file only once (work with HDD is slow we know)
- It will define API class only once
This way of implementation is not the best one. Of course there are a lot of community components like jomsocial, joomunity, CB, … And you probably integrate with all of them. So the best way in my opinion is to create abstract community integration layer.
Like for example JCommunityIntegration($component) abstract class and then add classes like JCommunityIntegrationTouch(), JCommunityIntegrationJomSocial(), … You know just like we do it with DB. Then you just all your JCommunityIntegration(‘Touch’) ro JCommunityIntegration($params->get(‘community_integration’)) where community_integration is a global parameter of your component. But that is only matter of style of programming.
Hope this article was helpful to you.

+1 (209) 800 1209