<?php
/**
 * @package    VP Advanced User
 * @author     Abhishek Das <info@virtueplanet.com>
 * @copyright  Copyright (C) 2012-2019 VirtuePlanet Services LLP. All rights reserved.
 * @license    GNU General Public License version 2 or later; see LICENSE.txt
 * @link       https://www.virtueplanet.com
 */

defined('_JEXEC') or die;

JHtml::addIncludePath(JPATH_ADVANCEDUSER_SITE . '/helpers/html');

JHtml::_('vpadvanceduser.stylesheet', 'com_vpadvanceduser/general.css', array(), true);

$article     = isset($displayData['article']) ? $displayData['article'] : null;
$author      = isset($displayData['author']) ? $displayData['author'] : null;
$params      = isset($displayData['params']) ? $displayData['params'] : null;
$position    = isset($displayData['position']) ? $displayData['position'] : null;
$link_author = isset($displayData['link_author']) ? $displayData['link_author'] : false;

if(empty($author) || empty($author->id) || !isset($author->vpadvanceduserdata))
{
	return '';
}

$profile             = $author->vpadvanceduserdata;
$has_profile_picture = isset($profile['profile_picture']);
$wrapper_class       = $has_profile_picture ? ' with-profile-picture' : '';
$wrapper_class       = $position ? $wrapper_class . ' ' . $position : $wrapper_class;
$author_name         = $author->get('name');

if(!empty($profile['firstname']))
{
	$author_name = $profile['firstname'];
	
	if(!empty($profile['lastname']))
	{
		$author_name .= ' ' . $profile['lastname'];
	}
}

$author_name = '<span itemprop="name">' . $author_name . '</span>';
?>
<div class="vp-wrapper vp-article-author<?php echo $wrapper_class ?>" itemprop="author" itemscope itemtype="https://schema.org/Person">
	<?php if($has_profile_picture) : ?>
		<div class="vp-profile-picture-cont">
			<span>
				<?php if (!empty($article->contact_link) && $link_author) : ?>
					<a href="<?php echo $article->contact_link ?>">
						<?php echo JHtml::_('vpaufield.avatar', $profile['profile_picture'], 'class="vp-profile-picture" alt="' . $this->escape($author->name) . '" itemprop="image"'); ?>
					</a>
				<?php else : ?>
					<?php echo JHtml::_('vpaufield.avatar', $profile['profile_picture'], 'class="vp-profile-picture" alt="' . $this->escape($author->name) . '" itemprop="image"'); ?>
				<?php endif ?>
			</span>
		</div>
	<?php endif; ?>
	<div class="vp-author-info">
		<?php if (!empty($article->contact_link) && $link_author) : ?>
			<h3 class="vp-author-name"><?php echo JHtml::_('link', $article->contact_link, $author_name, array('itemprop' => 'url')); ?></h3>
		<?php else :?>
			<h3 class="vp-author-name"><?php echo $author_name; ?></h3>
		<?php endif; ?>
		<?php if(!empty($profile['description'])) : ?>
		 <p class="vp-author-description" itemprop="description"><?php echo $profile['description'] ?></p>
		<?php endif ?>
		<?php if(!empty($profile['google_plus']) || !empty($profile['facebook']) || !empty($profile['twitter'])) : ?>
			<div class="vp-author-social-accounts">
				<ul class="vp-list-inline">
					<?php if(!empty($profile['google_plus'])) : ?>
						<li><?php echo JText::_('COM_VPADVANCEDUSER_FOLLOW_ON') ?>&nbsp;<?php echo JHtml::_('vpaufield.google_plus', $profile['google_plus']); ?></li>
					<?php endif ?>
					<?php if(!empty($profile['facebook'])) : ?>
						<li><?php echo JText::_('COM_VPADVANCEDUSER_FOLLOW_ON') ?>&nbsp;<?php echo JHtml::_('vpaufield.facebook', $profile['facebook']); ?></li>
					<?php endif ?>
					<?php if(!empty($profile['twitter'])) : ?>
						<li><?php echo JText::_('COM_VPADVANCEDUSER_FOLLOW_ON') ?>&nbsp;<?php echo JHtml::_('vpaufield.twitter', $profile['twitter']); ?></li>
					<?php endif ?>
				</ul>
			</div>
		<?php endif ?>
	</div>
</div>