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

defined('_JEXEC') or die;
use Joomla\CMS\Uri\Uri;
use Joomla\CMS\Factory;
use Joomla\CMS\Router\Route;
use Joomla\Registry\Registry;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Layout\LayoutHelper;
use Joomla\CMS\Language\Associations;

// Create a shortcut for params.
$params  = & $this->item->params;
$images  = json_decode($this->item->images);
$canEdit = $this->item->params->get('access-edit');
$info    = $params->get('info_block_position', 2);
$aInfo1 = ($params->get('show_publish_date') || $params->get('show_category') || $params->get('show_parent_category') || $params->get('show_author'));
$aInfo2 = ($params->get('show_create_date') || $params->get('show_modify_date') || $params->get('show_hits'));
$topInfo = ($aInfo1 && $info != 1) || ($aInfo2 && $info == 0);
$botInfo = ($aInfo1 && $info == 1) || ($aInfo2 && $info != 0);
$icons = $params->get('access-edit') || $params->get('show_print_icon') || $params->get('show_email_icon');

$timePublishDown = $this->item->publish_down != null ? $this->item->publish_down : '';
$timePublishUp = $this->item->publish_up != null ? $this->item->publish_up : '';
?>

<?php if ($this->item->state == 0 || strtotime($timePublishUp) > strtotime(Factory::getDate())
|| ((strtotime($timePublishDown) < strtotime(Factory::getDate())) && !in_array($this->item->publish_down,array('',Factory::getDbo()->getNullDate())) )) : ?>
<div class="system-unpublished">
<?php endif; ?>

	<!-- Article -->
	<article>
		<div class="image-wrap">
	      <?php echo LayoutHelper::render('joomla.content.intro_image', $this->item); ?>
	    </div>

    	<div class="intro-wrap">
    		<?php if ($params->get('show_title')) : ?>
					<?php echo LayoutHelper::render('joomla.content.item_title', array('item' => $this->item, 'params' => $params, 'title-tag'=>'h2')); ?>
				<?php endif; ?>

		    <!-- Aside -->
		    <?php if ($topInfo || $icons) : ?>
		    <aside class="article-aside clearfix">
		      <?php if ($topInfo): ?>
		      <?php echo LayoutHelper::render('joomla.content.info_block.block', array('item' => $this->item, 'params' => $params, 'position' => 'above')); ?>
		      <?php endif; ?>
		      
		      <?php if ($icons): ?>
		      <?php echo LayoutHelper::render('joomla.content.icons', array('item' => $this->item, 'params' => $params)); ?>
		      <?php endif; ?>
		    </aside>  
		    <?php endif; ?>
		    <!-- //Aside -->

				<section class="article-intro clearfix">

					<?php if (!$params->get('show_intro')) : ?>
						<?php echo $this->item->event->afterDisplayTitle; ?>
					<?php endif; ?>

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

					<?php //echo LayoutHelper::render('joomla.content.intro_image', $this->item); ?>

					<?php echo $this->item->introtext; ?>
				</section>

		    <!-- footer -->
		    <?php if ($botInfo) : ?>
		    <footer class="article-footer clearfix">
		      <?php echo LayoutHelper::render('joomla.content.info_block.block', array('item' => $this->item, 'params' => $params, 'position' => 'below')); ?>
		    </footer>
		    <?php endif; ?>
		    <!-- //footer -->

		    <?php if ($params->get('show_tags', 1) && !empty($this->item->tags)) : ?>
		      <?php echo LayoutHelper::render('joomla.content.tags', $this->item->tags->itemTags); ?>
		    <?php endif; ?>

				<?php if ($params->get('show_readmore')) :
					if ($params->get('access-view')) :
						$link = Route::_(ContentHelperRoute::getArticleRoute($this->item->slug, $this->item->catid, $this->item->language));
					else :
						$menu      = Factory::getApplication()->getMenu();
						$active    = $menu->getActive();
						$itemId    = $active->id;
						$link = new Uri(Route::_('index.php?option=com_users&view=login&Itemid=' . $itemId, false));
						$link->setVar('return', base64_encode(ContentHelperRoute::getArticleRoute($this->item->slug, $this->item->catid, $this->item->language)));
					endif; ?>

      	<?php echo LayoutHelper::render('joomla.content.readmore', array('item' => $this->item, 'params' => $params, 'link' => $link)); ?>
      
				<?php endif; ?>
    	</div>
	</article>
	<!-- //Article -->

  <?php if ($this->item->state == 0 || strtotime($timePublishUp) > strtotime(Factory::getDate())
	|| ((strtotime($timePublishDown) < strtotime(Factory::getDate())) && !in_array($this->item->publish_down,array('',Factory::getDbo()->getNullDate())) )) : ?>
	</div>
	<?php endif; ?>
<?php echo $this->item->event->afterDisplayContent; ?>
