• Page:
  • 1

Introducing uKnowvaFactory::getUser()->getProfileAnchor()

OFFLINE

Introducing uKnowvaFactory::getUser()->​getProfileAnchor()

3 years, 8 months ago
Many times you do not want to use the getSnapShot() function as you do not want the avatar and the div tags it adds to the return string, so you usually use strip tags, etc.

Now a better way to do so is use this:

echo uKnowvaFactory::getUser()->getProfileAnchor();


following is the function definition:

	/*
	 * added 2.4.4 onwards
	 * @auhtor: vicky
	 * gets a profile anchor link for the user 
	 * 
	 * @relative = false means a absolute link will be returned that is with the JURIroot(), etc, else a relative one
	 * @anchortext can be name, username, email, thumb or avatar
	 * $attributes can have all other options like class, id,title, etc etc for the <a> element
	 */
	function getProfileAnchor($relative = true, $attributes = array(),$anchor_text = 'name' ){
		if(empty($this->id))
			return 'NA'; 
		
		$anchor = '<a href="'.($relative ? 
					CRoute::_('index.php?option=com_community&view=profile&userid='.$this->id)
					:CRoute::_('index.php?option=com_community&view=profile&userid='.$this->id,false,-1)).'">%s</a>';
		
		$replace = '';
		switch(strtolower($anchor_text)){
			case 'username':
				$replace = $this->username;
				break;
			case 'email':
				$replace = $this->email;
				break;
			case 'avatar':
				require_once( JPATH_ROOT . DS . 'components' . DS . 'com_community' . DS . 'libraries' . DS . 'core.php' );
				$cuser = CFactory::getUser($this->id);
				$replace = '<img src="'.$cuser->getAvatar().'" alt= "'.$this->name.'" />';
				break;
			case 'avatar':
				require_once( JPATH_ROOT . DS . 'components' . DS . 'com_community' . DS . 'libraries' . DS . 'core.php' );
				$cuser = CFactory::getUser($this->id);
				$replace = '<img src="'.$cuser->getThumbAvatar().'" alt= "'.$this->name.'" />';
				break;
			case 'name':
			default:	
				$replace = $this->name;
				break;
		}
		
		return sprintf($anchor,$replace);
	}
Last Edit: 3 years, 8 months ago by Vicky Jain.
The following user(s) said Thank You: Adarsh Surania
  • Page:
  • 1

Upcoming Events

No events found.

Who's Online

2 users online