<?php
/**
 * Pojedyncza strona
 *
 * @link https://krzysztof-turek.com
 *
 * @package tylkofotografia.pl
 * @version 0.1
 */

get_header();
global $post;
global $wpdb;

$upload_dir = wp_upload_dir();

$image = $wpdb->get_row(
    "SELECT * FROM {$wpdb->prefix}responsive_images where  `img_filetype` in ('jpg', 'png') and `img_size` = 'hr' and `img_post_id` = " .
        get_post_thumbnail_id($post->ID)
);
$webp = $wpdb->get_row(
    "SELECT * FROM {$wpdb->prefix}responsive_images where  `img_filetype` in ('webp') and `img_size` = 'hr' and `img_post_id` = " .
        get_post_thumbnail_id($post->ID)
);
if (wp_is_mobile()) {
    $image = $wpdb->get_row(
        "SELECT * FROM {$wpdb->prefix}responsive_images where  `img_filetype` in ('jpg', 'png') and `img_size` = 'hrmb' and `img_post_id` = " .
            get_post_thumbnail_id($post->ID)
    );
    $webp = $wpdb->get_row(
        "SELECT * FROM {$wpdb->prefix}responsive_images where  `img_filetype` in ('webp') and `img_size` = 'hrmb' and `img_post_id` = " .
            get_post_thumbnail_id($post->ID)
    );
}
if (!empty($image)) {
    $time = filemtime($upload_dir["basedir"] . $image->img_location);
}
if (!empty($webp)) {
    $webpset = '"' . $upload_dir["baseurl"] . $image->img_location . '" type("image/webp"), ';
} else {
    $webpset = "";
}
if (!empty($image)) {
    $jpgpset = '"' . $upload_dir["baseurl"] . $image->img_location . '" type("image/jpg")';
 ?>

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
	<?php if(!wp_is_mobile()) { ?>
<div class="page-hero" style='background-image: linear-gradient(0deg, rgba(28,47,64,0.7),rgba(47,72,103,0.7)), url("<?php echo $upload_dir["baseurl"] . $webp->img_location; ?>?x=<?php echo $time ?>");  background-repeat: no-repeat; background-position: top; background-size: cover; height:585px'>
	<div class="container col-lg-6 col-xs-12">
		<div class="row" style="color:#fff">
			<div style="padding-top: calc(18% + 190px)">
				<h1 class="post-title text-center mb-5" ><?php the_title(); ?></h1>
		<?php the_excerpt() ?>
		<?php get_template_part('template-parts/content/content-meta'); ?>
				</div>
			</div>
		</div>
	</div>
<article class="container col-lg-8 col-xs-12 test4">
	<?php } else { ?>

<div >
			<div class="img-container" style='margin-top: 70px;'>

					<figure class="wp-caption image">
						<picture>
							<source srcset="<?php echo $upload_dir["baseurl"] . webp->img_location; ?>?x=<?php echo $time ?>" type="image/webp">
  							<source srcset="<?php echo $upload_dir["baseurl"] . $image->img_location; ?>?x=<?php echo $time ?>" type="image/jpeg"> 
							<img src="<?php echo $upload_dir["baseurl"] . $image->img_location; ?>?x=<?php echo $time ?>">
						</picture>
					</figure>

					<div class="overlay">

						<div class="text">
								<div style="padding-top: 0px">
										<h1 class="post-title text-center mb-5" ><?php the_title(); ?></h1>
								<?php the_excerpt() ?>
								<?php get_template_part('template-parts/content/content-meta-mb'); ?>
										</div>
									</div>
								</div>
						</div>
					</div>

			<article class="container col-lg-8 col-xs-12 test4">

		<?php } ?>





		<div class="row">
			<div class="col-lg-8 col-xs-12">

			<nav id="breadcrumbs" class="breadcrumbs mb-5"><?php echo Breadcrumbs::postBreadcrumbs() ?></nav>

<?php the_content(); ?>
</div>
			<aside class="col-lg-4 col-xs-12"><?php get_sidebar(); ?></aside>
	</div>
	</article>

<?php endwhile; else:

				get_template_part('template-parts/content/content-none');

			endif;
} else {
				?>
<main class="content" id="main">

	<article class="container col-lg-6 col-xs-12 test2">
		<div class="row">
			<div>

			<nav id="breadcrumbs" class="breadcrumbs mb-5"><?php echo Breadcrumbs::postBreadcrumbs() ?></nav>
				<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-2401815550643539"
     crossorigin="anonymous">
				</script>
<!-- Sidebar -->
<ins class="adsbygoogle"
     style="display:block"
     data-ad-client="ca-pub-2401815550643539"
     data-ad-slot="6894360927"
     data-ad-format="auto"
     data-full-width-responsive="true"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
				<?php if (have_posts()) : while (have_posts()) : the_post(); ?>

					<?php the_excerpt() ?>

					<?php get_template_part('template-parts/content/content-meta'); ?>

					<h1 class="post-title text-center mb-5"><?php the_title(); ?></h1>

					<?php the_content(); ?>
			</div>
					<?php wp_link_pages(array('before' => '<p><strong>Strona:</strong> ', 'after' => '</p>', 'next_or_number' => 'number')); ?>

			<?php endwhile; else:

				get_template_part('template-parts/content/content-none');

			endif; ?>
			</div>
		</div>
	</article>
</main>
<?php
			} ?>

<?php	comments_template();
	get_footer();