<?php

// no direct access
defined('_JEXEC') or die;

JLoader::register('TagsHelperRoute', JPATH_BASE . '/components/com_tags/helpers/route.php');

// Create a shortcut for params.
$params = &$this->item->params;
$images = json_decode($this->item->images);
$canEdit	= $this->item->params->get('access-edit');
?>

<article class="itemView">
	<?php  if (isset($images->image_intro) and !empty($images->image_intro)) : ?>
	<div class="itemImageBlock">
		<a href="<?php echo JRoute::_(ContentHelperRoute::getArticleRoute($this->item->slug, $this->item->catid, $this->item->language)); ?>" class="itemImage img-intro-<?php echo $images->float_intro ? $images->float_intro : $params->get('float_intro'); ?>">
			<img
				<?php if ($images->image_intro_caption):
					echo 'class="caption"'.' title="' .$images->image_intro_caption .'"';
				endif; ?>
				<?php if (!empty($images->image_intro)):?>
					style="float:<?php echo  $params->get('float_intro') ?>"
				<?php else: ?>
					style="float:<?php echo  $images->float_intro ?>"
				<?php endif; ?>
				src="<?php echo $images->image_intro; ?>" alt="<?php echo $images->image_intro_alt; ?>"/>
		</a>
	</div>
	<?php endif; ?>
	
	<div class="itemBlock">
		<?php if ($params->get('show_title')) : ?>
		<header>
			<h2 itemprop="name">
				<?php if ($params->get('link_titles') && $params->get('access-view')) : ?>
					<a href="<?php echo JRoute::_(ContentHelperRoute::getArticleRoute($this->item->slug, $this->item->catid, $this->item->language)); ?>">
					<?php echo $this->escape($this->item->title); ?></a>
				<?php else : ?>
					<?php echo $this->escape($this->item->title); ?>
				<?php endif; ?>
			</h2>
		</header>
		<?php endif; ?>
		
		<?php if(($params->get('show_author') && !empty($this->item->author))): ?>
		<div class="itemInfoBlock"> 
				<?php if($params->get('show_publish_date')) : ?>
				<time datetime="<?php echo JHtml::_('date', $this->item->publish_up, JText::_(DATE_W3C)); ?>" itemprop="datePublished">
					<?php echo JHTML::_('date', $this->item->publish_up, 'd.m.Y'); ?>
				</time>
				<?php elseif($params->get('show_create_date')) : ?>
				<time datetime="<?php echo JHtml::_('date', $this->item->created, JText::_(DATE_W3C)); ?>" itemprop="dateModified">
					<?php echo JHTML::_('date', $this->item->created, 'd.m.Y'); ?>
				</time>
				<?php endif; ?>
				
				<span itemprop="author" itemscope itemtype="http://schema.org/Person">          
		          <span itemprop="name">
		          <?php $author = $this->item->created_by_alias ? $this->item->created_by_alias : $this->item->author; ?>
		          <?php if (!empty($this->item->contactid) && $params->get('link_author') == true): ?>
		          <?php
		          		$needle = 'index.php?option=com_contact&view=contact&id=' . $this->item->contactid;
		          		$menu = JFactory::getApplication()->getMenu();
		          		$item = $menu->getItems('link', $needle, true);
		          		$cntlink = !empty($item) ? $needle . '&Itemid=' . $item->id : $needle;
		          	?>
			          <?php echo JText::_('TPL_GK_LANG_BY'); ?>
			          <?php echo JHtml::_('link', JRoute::_($cntlink), $author); ?>
		          <?php else: ?>
			          <?php echo JText::_('TPL_GK_LANG_BY'); ?>
			          <?php echo $author; ?>
		          <?php endif; ?>
		         </span>
		      </span> 
		 </div>
		<?php endif; ?>
		
		<div class="itemBody itemIntroText gk-clearfix">
			<?php echo $this->item->event->afterDisplayTitle; ?>
			
			<?php if ($params->get('show_intro')) : ?>
				<?php echo $this->item->event->beforeDisplayContent; ?>
				<?php echo $this->item->introtext; ?>
			<?php endif; ?>
			
			<?php if ($params->get('show_tags', 1) && !empty($this->item->tags->itemTags)) : ?>
		    <div class="tags"><span class="tags-label"><?php echo JText::sprintf('TPL_GK_LANG_TAGGED_UNDER'); ?></span>
		       
		    	<?php foreach ($this->item->tags->itemTags as $tag) : ?>
		        <a href="<?php echo JRoute::_(TagsHelperRoute::getTagRoute($tag->tag_id . ':' . $tag->alias)) ?>"><?php echo $tag->title; ?></a>
		    	<?php endforeach; ?>
		    </div>
			<?php endif; ?>
			
			<?php if ($params->get('show_readmore') && $this->item->readmore) :
				if ($params->get('access-view')) :
					$link = JRoute::_(ContentHelperRoute::getArticleRoute($this->item->slug, $this->item->catid, $this->item->language));
				else :
					$menu = JFactory::getApplication()->getMenu();
					$active = $menu->getActive();
					$itemId = $active->id;
					$link1 = JRoute::_('index.php?option=com_users&view=login&Itemid=' . $itemId);
					$returnURL = JRoute::_(ContentHelperRoute::getArticleRoute($this->item->slug, $this->item->catid, $this->item->language));
					$link = new JURI($link1);
					$link->setVar('return', base64_encode($returnURL));
				endif;
			?>
			<a class="button" href="<?php echo $link; ?>">
				<?php if (!$params->get('access-view')) :
					echo JText::_('COM_CONTENT_REGISTER_TO_READ_MORE');
				elseif ($readmore = $this->item->alternative_readmore) :
					echo $readmore;
					if ($params->get('show_readmore_title', 0) != 0) :
					    echo JHtml::_('string.truncate', ($this->item->title), $params->get('readmore_limit'));
					endif;
				elseif ($params->get('show_readmore_title', 0) == 0) :
					echo str_replace('...', '', JText::sprintf('COM_CONTENT_READ_MORE_TITLE'));
				else :
					echo JText::_('COM_CONTENT_READ_MORE');
					echo JHtml::_('string.truncate', ($this->item->title), $params->get('readmore_limit'));
				endif; ?>
			</a>
			<?php endif; ?>
		</div>
	</div>
</article>

<?php echo $this->item->event->afterDisplayContent; ?>