<?php
/**
 * Custom template tags for this theme
 *
 * Eventually, some of the functionality here could be replaced by core features.
 *
 * @package nextpage
 */
if ( ! defined( 'ABSPATH' ) ) {
	exit(); //exit if access directly
}

if ( ! class_exists( 'Nextpage_Tags' ) ) {
	class Nextpage_Tags {

		private static $instance;

		public $nextpageFunctions;

		public function __construct() {
			$this->nextpageFunctions = Nextpage_Function( 'Functions' );
		}

		/**
		 * get instance
		 * @since 1.0.0
		 * */
		public static function getInstance() {
			if ( null == self::$instance ) {
				self::$instance = new self();
			}

			return self::$instance;
		}

		/**
		 * Prints HTML with meta information for the current post-date/time.
		 */
		public static function posted_on() {
			$time_string = '<time class="entry-date published updated" datetime="%1$s">%2$s</time>';
			if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
				$time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time><time class="updated" datetime="%3$s">%4$s</time>';
			}

			$time_string = sprintf( $time_string,
				esc_attr( get_the_date( DATE_W3C ) ),
				esc_html( get_the_date() ),
				esc_attr( get_the_modified_date( DATE_W3C ) ),
				esc_html( get_the_modified_date() )
			);

			$posted_on = sprintf(
			/* translators: %s: post date. */
				esc_html_x( '%s', 'post date', 'nextpage' ), // phpcs:ignore WordPress.WP.I18n.NoEmptyStrings
				'<a href="' . esc_url( get_permalink() ) . '" rel="bookmark">' . $time_string . '</a>'
			);

			echo '<span class="date"><i class="fa fa-calendar"></i>' . $posted_on . '</span>'; // WPCS: XSS OK.

		}

		/**
		 * Prints HTML with meta information for the current post-date/time.
		 */
		public static function posted_on_two() {
			$time_string = '<time class="entry-date published updated" datetime="%1$s">%2$s</time>';
			if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
				$time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time><time class="updated" datetime="%3$s">%4$s</time>';
			}

			$time_string = sprintf( $time_string,
				esc_attr( get_the_date( DATE_W3C ) ),
				esc_html( get_the_date() ),
				esc_attr( get_the_modified_date( DATE_W3C ) ),
				esc_html( get_the_modified_date() )
			);

			$posted_on = sprintf(
			/* translators: %s: post date. */
				esc_html_x( '%s', 'post date', 'nextpage' ), // phpcs:ignore WordPress.WP.I18n.NoEmptyStrings
				'<a href="' . esc_url( get_permalink() ) . '" rel="bookmark">' . $time_string . '</a>'
			);

			echo '<span class="date"><i class="fa fa-clock-o"></i>' . $posted_on . '</span>'; // WPCS: XSS OK.

		}

		public static function posted_by() {
			$byline = sprintf(
			/* translators: %s: post author. */
				esc_html_x( '%s', 'post author', 'nextpage' ), // phpcs:ignore WordPress.WP.I18n.NoEmptyStrings
				'<span class="author vcard"><i class="fa fa-user"></i><a class="url fn n" href="' . esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ) . '">' . esc_html( get_the_author() ) . '</a></span>'
			);

			echo wp_kses_post( $byline ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped

		}


		/**
		 * Displays an optional post thumbnail.
		 *
		 * Wraps the post thumbnail in an anchor element on index views, or a div
		 * element when on single views.
		 */
		public function post_thumbnail() {
			if ( post_password_required() || is_attachment() || ! has_post_thumbnail() ) {
				return;
			}

			$img_id    = get_post_thumbnail_id( get_the_ID() );
			$image_alt = get_post_meta( $img_id, '_wp_attachment_image_alt', true );
			$src       = wp_get_attachment_image_src( get_post_thumbnail_id( get_the_ID() ), 'full', false, '' );


			if ( is_singular() ) :
				?>

                <div class="thumb">
					<?php the_post_thumbnail( 'nextpage-blog-details' ); ?>
                </div><!-- .post-thumbnail -->

			<?php else : ?>
				<?php if ( function_exists( 'Aq_Resize' ) ) :
					if ( 'video' == get_post_format() ) :
						$videoid = $this->nextpageFunctions->meta_query( 'nextpage_post_video', 'videoid' );
						?>
                        <div class="thumb" aria-hidden="true" tabindex="-1">
                            <img src="<?php echo esc_url( Aq_Resize( $src[0], 1155, 464, true ) ); ?>"
                                 alt="<?php echo esc_attr( $image_alt ); ?>">
							<?php if ( ! empty( $videoid ) ) : ?>
                                <a class="video-play-btn" href="https://www.youtube.com/embed/Wimkqo8gDZ0"
                                   data-effect="mfp-zoom-in"><i class="fa fa-play"></i></a>
							<?php endif; ?>
                        </div>
					<?php else: ?>
                        <a class="thumb" href="<?php the_permalink(); ?>" aria-hidden="true" tabindex="-1">
                            <img src="<?php echo esc_url( Aq_Resize( $src[0], 1155, 464, true ) ); ?>"
                                 alt="<?php echo esc_attr( $image_alt ); ?>">
                        </a>
					<?php endif; ?>
				<?php else: ?>
                    <a class="thumb" href="<?php the_permalink(); ?>" aria-hidden="true" tabindex="-1">
						<?php
						the_post_thumbnail( 'post-thumbnail', array(
							'alt' => the_title_attribute( array(
								'echo' => false,
							) ),
						) );
						?>
                    </a>
				<?php endif; ?>
			<?php
			endif; // End is_singular().
		}


		/**
		 * Displays an optional post thumbnail.
		 *
		 * Wraps the post thumbnail in an anchor element on index views, or a div
		 * element when on single views.
		 */
		public function archive_post_thumbnail() {
			if ( post_password_required() || is_attachment() || ! has_post_thumbnail() ) {
				return;
			}
			$img_id    = get_post_thumbnail_id( get_the_ID() );
			$image_alt = get_post_meta( $img_id, '_wp_attachment_image_alt', true );
			$src       = wp_get_attachment_image_src( get_post_thumbnail_id( get_the_ID() ), 'full', false, '' );
			if ( function_exists( 'Aq_Resize' ) ) :
				?>

                <a class="thumb" href="<?php the_permalink(); ?>" aria-hidden="true" tabindex="-1">
                    <img src="<?php echo esc_url( Aq_Resize( $src[0], 368, 230, true ) ); ?>"
                         alt="<?php echo esc_attr( $image_alt ); ?>">
                </a>
			<?php else: ?>
                <a class="thumb" href="<?php the_permalink(); ?>" aria-hidden="true" tabindex="-1">
					<?php
					the_post_thumbnail( 'post-thumbnail', array(
						'alt' => the_title_attribute( array(
							'echo' => false,
						) ),
					) ); ?>
                </a>
			<?php endif;


		}

		public static function tags() {
			?>
			<?php if ( has_tag() ): ?>
                <div class="tags">
                    <span><?php echo esc_html__( 'Tags:', 'nextpage' ); ?></span>
					<?php
					if ( get_the_tag_list() ) {
						echo get_the_tag_list( ' ', ', ', '' );
					}
					?>
                </div>
			<?php endif; ?>

		<?php }


	}//end class


}
