<?php
/**
 * @package     Joomla.Site
 * @subpackage  Layout
 *
 * @copyright   Copyright (C) 2005 - 2016 Open Source Matters, Inc. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

defined('JPATH_BASE') or die;
$item = $displayData['item'];
$author = ($item->created_by_alias ? $item->created_by_alias : $item->author);

require_once(__DIR__.'/../../../../../helper.php');

$customs = JATemplateHelper::getCustomFields($item->created_by, 'user');

?>

<?php if(JFactory::getApplication()->input->get('view') == 'article') :?>
  <dd class="field-entry r-author r-class" itemprop="author" title="<?php echo JText::sprintf('COM_CONTENT_WRITTEN_BY', ''); ?>"> 
    <span class="field-label l-author"><?php echo Jtext::_('TPL_AUTHOR'); ?></span>
    <span class="field-value">

    <?php if (!empty($displayData['item']->contact_link )) : ?><a href="<?php echo $displayData['item']->contact_link; ?>" title="<?php echo $author; ?>" ><?php endif; ?>
    <img class="author-avatar" src="<?php if(!empty($customs['avatar'])): echo $customs['avatar']; else: echo 'images/joomlart/team/default.png'; endif; ?>" alt="<?php echo $author; ?>" title="<?php echo $author; ?>" />
    <?php if (!empty($displayData['item']->contact_link )) : ?></a><?php endif; ?>

    <?php if (!empty($displayData['item']->contact_link )) : ?>
      <span class="author-name" itemprop="name"><?php echo JHtml::_('link', $displayData['item']->contact_link, $author, array('itemprop' => 'url')); ?></span>
    <?php else :?>
      <span class="author-name" itemprop="name"><?php echo $author; ?></span>
    <?php endif; ?>

    <span style="display: none;" itemprop="publisher">
    <span itemprop="logo" itemscope itemtype="https://schema.org/ImageObject">
      <img src="<?php echo JURI::base(); ?>/templates/<?php echo JFactory::getApplication()->getTemplate() ?>/images/logo.png" alt="logo" itemprop="url" />
      <meta itemprop="width" content="auto" />
      <meta itemprop="height" content="auto" />
    </span>
    <meta itemprop="name" content="<?php echo $author; ?>"/>
    </span>
    </span>
  </dd>
<?php else :?>
  <div class="field-entry r-author r-class" title="<?php echo JText::sprintf('COM_CONTENT_WRITTEN_BY', ''); ?>"> 
    <span class="field-label l-author"><?php echo Jtext::_('TPL_AUTHOR'); ?></span>
    <span class="field-value">

    <?php if (!empty($displayData['item']->contact_link )) : ?><a href="<?php echo $displayData['item']->contact_link; ?>" title="<?php echo $author; ?>" ><?php endif; ?>
    <img class="author-avatar" src="<?php if(!empty($customs['avatar'])): echo $customs['avatar']; else: echo 'images/joomlart/team/default.png'; endif; ?>" alt="<?php echo $author; ?>" title="<?php echo $author; ?>" />
    <?php if (!empty($displayData['item']->contact_link )) : ?></a><?php endif; ?>

    <?php if (!empty($displayData['item']->contact_link )) : ?>
      <span class="author-name"><?php echo JHtml::_('link', $displayData['item']->contact_link, $author, array('itemprop' => 'url')); ?></span>
    <?php else :?>
      <span class="author-name"><?php echo $author; ?></span>
    <?php endif; ?>
    </span>
  </div>
<?php endif;?>