1. Home
  2. Docs
  3. Confluence
  4. Confluence User Macros
  5. Business Card

Business Card

Summary

This Confluence user macro displays

  • single user profile info
  • group members profile info
  • panel display optional

Source Code

#* ============================================================================
 * BUSINESS CARD
 *
 * This Confluence user macro displays
 * - single user profile info
 * - group members profile info
 * - panel display optional
 *
 * Version: 4.0.1
 * Date:    2018-06-26
 * Author:  George Lewe
 * Source:  https://github.com/glewe/business-card
 * License: GNU LGPLv3
 *
 * Macro body:      Yes
 * Body processing: Rendered
 *#

#* ----------------------------------------------------------------------------
 * PARAMETER
 *#
## @param user:title=Username|type=username|required=false|desc=If "Single user" is checked, specify the username here.|default=
## @param GroupUsers:title=Group Users|type=boolean|desc=Select this option if you want to display the business card of all users in a group. Use the text box below to specify the group name. If you select this option, the username above is ignored.|default=false
## @param group:title=Group name|type=string|required=false|desc=If "Single user" is unchecked, specify the group name here.|default=
## @param ShowPanel:title=Show Panel|type=boolean|desc=Select whether to show a panel around the profile information.|default=true
## @param PanelBorderColor:title=Panel Border Color|type=string|desc=Enter the panel border color in hexadecimal starting with a #.|default=#CCCCCC
## @param showBody:title=Custom Text|type=boolean|required=false|desc=Select this option if you want to use the macro body to display a custom text at the bottom of the business card. If this option is unchecked, the body will be ignored.|default=false

#* ----------------------------------------------------------------------------
 * VARIABLES AND INPUT
 *#
#set($containerManagerClass = $content.class.forName('com.atlassian.spring.container.ContainerManager'))
#set($getInstanceMethod = $containerManagerClass.getDeclaredMethod('getInstance',null))
#set($containerManager = $getInstanceMethod.invoke(null,null))
#set($containerContext = $containerManager.containerContext)
#set($userDetailsManager = $containerContext.getComponent('userDetailsManager'))
#set($personalInformationManager = $containerContext.getComponent('personalInformationManager'))
#set($wikiStyleRenderer = $containerContext.getComponent('wikiStyleRenderer'))
#set($users = [])

#if ($paramGroupUsers==false && $paramuser != "")

   ## Single User
   ## Setting $tmp is workaround to stop boolean output
   #set ($tmp = $users.add($paramuser))

#elseif ($paramgroup != "")

   ## All Users in Group
   #set($group = $userAccessor.getGroup($paramgroup))
   #if ($group)
      #set($users = $userAccessor.getMemberNamesAsList($group))
   #end
   
#end

#if (!$paramPanelBorderColor)
   #set ($paramPanelBorderColor="#CCCCCC")
#end

#* -------------------------------------------------------------------------
 * BUBBLE SORT BY FULL NAME
 *#

#*
 * Create an array that we can sort
 *#
#set( $uarray = [] )
#set( $unarray = [] )

#*
 * Now fill it with the full names
 *#
#set ( $count = 0 )
#foreach( $user in  $users )
   #set( $fullName = $uarray.add( $userAccessor.getUserByName($user).getFullName() ) )
   #set( $un = $unarray.add( $user) )
   #set ( $count = $count + 1 )
#end

#*
 * Bubble Sort
 * Takes n^2 passes
 *#
#set($size=$uarray.size())
#foreach($junk in $uarray)
   #set($actual=-1)
   #foreach($line in $uarray)
      #set($actual=$actual+1)
      #if($velocityCount<$size)
         #*
          * Compare this and previous. If this is smaller, swap.
          *#
         #if ($line.compareToIgnoreCase($uarray.get($velocityCount)) > 0 )
            #set ($tmp=$uarray.get($velocityCount))
            #set ($junk=$uarray.set($velocityCount,$line))
            #set ($junk=$uarray.set($actual,$tmp))

            #*
             * Sort usernames together with fullnames as map is not available in confluence velocity version
             *#
            #set ($tmp2=$unarray.get($velocityCount))
            #set ($junk=$unarray.set($velocityCount, $unarray.get($actual)))
            #set ($junk=$unarray.set($actual, $tmp2))
         #end
      #end
   #end
#end

#* -------------------------------------------------------------------------
 * OUTPUT
 *#
#foreach ($item in $unarray)
   
   #*
    * Collect user information
    *#
   #set( $user = $userAccessor.getUserIfAvailable($item)  )
   #set( $pi = $personalInformationManager.getPersonalInformation($user) )
   #set( $userAvatarPath = $userAccessor.getUserProfilePicture($item).getDownloadPath() )
   #set( $userFullname = $user.fullName )
   #set( $userUsername = $user.name )
   #set( $userEmail = $user.email )
   #set( $userPhone = $userDetailsManager.getStringProperty($user, 'phone') )
   #set( $userIM = $userDetailsManager.getStringProperty($user, 'im') )
   #set( $userWebsite = $userDetailsManager.getStringProperty($user, 'website') )
   #set( $userPosition = $userDetailsManager.getStringProperty($user, 'position') )
   #set( $userDepartment = $userDetailsManager.getStringProperty($user, 'department') )
   #set( $userLocation = $userDetailsManager.getStringProperty($user, 'location') )
   #set( $userAboutMe = $wikiStyleRenderer.convertWikiToXHtml($pi.toPageContext(), $pi.getBodyAsString()) )
   
   #*
    * Show panel if selected
    *#
   #if ($paramShowPanel==true)
   <ac:structured-macro ac:name="panel">
      <ac:parameter ac:name="bgColor">#F8F8F8</ac:parameter>
      <ac:parameter ac:name="borderStyle">solid</ac:parameter>
      <ac:parameter ac:name="borderColor">$paramPanelBorderColor</ac:parameter>
      <ac:parameter ac:name="borderWidth">1</ac:parameter>
      <ac:rich-text-body>
   #end
         #*
         * Show profile
         *#
         <div class="profile-macro conf-macro output-block" data-hasbody="false" data-macro-name="profile">
            <div class="vcard">
               <span class="aui-avatar aui-avatar-large">
                  <span class="aui-avatar-inner">
                     <a class="userLogoLink" data-username="$userUsername" href="/display/~$userUsername
"><img class="userLogo logo" src="$userAvatarPath" alt="User icon: $userUsername" title="$userUsername"/></a>
                  </span>
               </span>
               <div class="values">
                  <p style="font-weight:bold;"><a href="/display/~$userUsername
" class="url fn confluence-userlink" data-username="$userUsername">$userFullname</a></p>
                  <a href="mailto:$userEmail" title="Send Email to $userFullname" class="email">$userEmail</a>
               </div>
            </div>
            <table class="profile-info profile-full">
               <tbody>
                  #if ($userPhone)
                  <tr>
                     <th>$action.getText('confluence.user.profile.phone'):</th>
                     <td>$userPhone</td>
                  </tr>
                  #end
                  #if ($userIM)
                  <tr>
                     <th>$action.getText('confluence.user.profile.im'):</th>
                     <td>$userIM</td>
                  </tr>
                  #end
                  #if ($userWebsite)
                  <tr>
                     <th>$action.getText('confluence.user.profile.website'):</th>
                     <td>$userWebsite</td>
                  </tr>
                  #end
                  #if ($userPosition)
                  <tr>
                     <th>$action.getText('confluence.user.profile.position'):</th>
                     <td>$userPosition</td>
                  </tr>
                  #end
                  #if ($userDepartment)
                  <tr>
                     <th>$action.getText('confluence.user.profile.department'):</th>
                     <td>$userDepartment</td>
                  </tr>
                  #end
                  #if ($userLocation)
                  <tr>
                     <th>$action.getText('confluence.user.profile.location'):</th>
                     <td>$userLocation</td>
                  </tr>
                  #end
               </tbody>
            </table>
         </div>
         #if ($paramGroupUsers==false && $paramshowBody==true)
            ## Set $body to avoid output of 'body')
            #set($body = $body)
            <p>$body</p>
         #end
   #if ($paramShowPanel==true)
      </ac:rich-text-body>
   </ac:structured-macro>
   #end
#end

#* -------------------------------------------------------------------------
 * OUTPUT
 *#
<style type="text/css">
   .profile-macro {color: #000066;}
   .profile-macro .profile-info th.confluenceTh, .profile-macro .profile-info td, .profile-macro .profile-info th {text-align:left;background-color:transparent !important;border:0px;}
   .profile-macro .vcard .userLogo {margin-bottom:10px;}
   .profile-macro .vcard .values {width:300px;}
   .profile-macro a {font-size:14px;}
</style>
Was this article helpful to you? Yes No

Leave a Reply

Your email address will not be published. Required fields are marked *