<?php
/**
 * Get partial layouts
 *
 * @package WordPress
 * @subpackage Charity
 * @since Charity 1.0
 */
/*------------------------------------------------------------
	Get Post featured image
============================================================*/
if ( !function_exists( 'wplook_get_post_featured_image' ) ) :
	function wplook_get_post_featured_image() { ?>
		<?php if ( has_post_thumbnail() ) : ?>
			<div class="post-image">
				<a href="<?php the_permalink(); ?>">
					<?php the_post_thumbnail('large-event'); ?>
				</a>
			</div><!-- /.post-image -->
		<?php endif; ?>
	<?php }
endif;
add_action( 'wplook_post_featured_image', 'wplook_get_post_featured_image' );

/*------------------------------------------------------------
	Get Post Gallery Images
============================================================*/
if ( !function_exists( 'wplook_get_post_gallery_image' ) ) :
	function wplook_get_post_gallery_image() {
	global $post;
	$page_id = $post->ID;
	$post_img_gallery = get_post_gallery( $page_id, false ); ?>
		<?php if (array_key_exists('ids', $post_img_gallery)) :
			$post_img_gallery_ids = explode( ",", $post_img_gallery['ids'] );
				$image_list = '<div class="post-image"><ul class="owl-carousel">';
				foreach( $post_img_gallery_ids as $id ) {
					$img_thumb   = wp_get_attachment_image_src ( $id, 'large-event');
					$image_list .= '<li><img src="' . esc_url($img_thumb["0"]) . '" /></li>';
				}
				$image_list .= '</ul></div><!-- /.post-image -->';
			echo   $image_list; ?>
		<?php else : ?>
			<?php do_action( 'wplook_post_featured_image' ); ?>
		<?php endif; ?>
	<?php }
endif;
add_action( 'wplook_post_gallery_image', 'wplook_get_post_gallery_image' );

/*------------------------------------------------------------
	Get Post video
============================================================*/
if ( !function_exists( 'wplook_get_post_video' ) ) :
	function wplook_get_post_video() { ?>
		<div class="fluid-width-video-wrapper">
			<?php the_content(); ?>
		</div>
	<?php }
endif;
add_action( 'wplook_post_video', 'wplook_get_post_video' );

/*------------------------------------------------------------
	Get Post video
============================================================*/
if ( !function_exists( 'wplook_get_post_audio' ) ) :
	function wplook_get_post_audio() { ?>
		<div class="audio-post">
			<?php the_content(); ?>
		</div>
	<?php }
endif;
add_action( 'wplook_post_audio', 'wplook_get_post_audio' );

/*------------------------------------------------------------
	Get Post video
============================================================*/
if ( !function_exists( 'wplook_get_post_link' ) ) :
	function wplook_get_post_link() { ?>
		<div class="link-post">
			<?php the_content(); ?>
		</div>
	<?php }
endif;
add_action( 'wplook_post_link', 'wplook_get_post_link' );

/*------------------------------------------------------------
	Get Post Meta
============================================================*/
if ( !function_exists( 'wplook_get_post_meta' ) ) :
	function wplook_get_post_meta() { ?>
		<div class="post-meta">
			<ul>
				<?php if (ot_get_option('wpl_author_single_post') == "on") : ?>
					<li>
						<a href="<?php echo esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ); ?>" title="<?php the_author(); ?>" class="post-author">
							<span class="post-author-image">
								<?php echo get_avatar(get_the_author_meta( 'ID' ), 55); ?>
							</span>
							<span class="post-author-name"><?php the_author_meta('display_name'); ?></span>
						</a>
					</li>
				<?php endif; ?>
				<?php if (ot_get_option('wpl_date_single_post') == "on") : ?>
					<li>
						<i class="far fa-calendar-alt"></i> <?php the_time( get_option( 'date_format' ) ); ?>
					</li>
				<?php endif; ?>
				<?php if (ot_get_option('wpl_comments_single_post') == "on") : ?>
					<li>
						<a href="<?php the_permalink(); ?>#comments">
							<i class="far fa-comments"></i> <?php echo get_comments_number(); ?>
						</a>
					</li>
				<?php endif; ?>
				<?php if (ot_get_option('wpl_like_single_post') == "on") : ?>
					<?php echo wplook_get_post_like(get_the_ID()); ?>
				<?php endif; ?>
			</ul>
		</div><!-- /.post-meta -->
	<?php }
endif;
add_action( 'wplook_post_meta', 'wplook_get_post_meta' );

/*------------------------------------------------------------
	Get Post Meta for List of post
============================================================*/
if ( !function_exists( 'wplook_get_list_post_meta' ) ) :
	function wplook_get_list_post_meta() { ?>
		<div class="post-meta">
			<ul>
				<?php if (ot_get_option('wpl_author_blog_post') == "on") : ?>
					<li>
						<a href="<?php echo esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ); ?>" title="<?php the_author(); ?>" class="post-author">
							<span class="post-author-image">
								<?php echo get_avatar(get_the_author_meta( 'ID' ), 55); ?>
							</span>
							<span class="post-author-name"><?php the_author_meta('display_name'); ?></span>
						</a>
					</li>
				<?php endif; ?>
				<?php if (ot_get_option('wpl_date_blog_post') == "on") : ?>
					<li>
						<i class="far fa-calendar-alt"></i> <?php the_time( get_option( 'date_format' ) ); ?>
					</li>
				<?php endif; ?>
				<?php if (ot_get_option('wpl_comments_blog_post') == "on") : ?>
					<li>
						<a href="<?php the_permalink(); ?>#comments">
							<i class="far fa-comments"></i> <?php echo get_comments_number(); ?>
						</a>
					</li>
				<?php endif; ?>
				<?php if (ot_get_option('wpl_like_blog_post') == "on") : ?>
					<?php echo wplook_get_post_like(get_the_ID()); ?>
				<?php endif; ?>
			</ul>
		</div><!-- /.post-meta -->
	<?php }
endif;
add_action( 'wplook_list_post_meta', 'wplook_get_list_post_meta' );

/*------------------------------------------------------------
	Get Post Body
============================================================*/
if ( !function_exists( 'wplook_get_post_body' ) ) :
	function wplook_get_post_body() {
		global $post;
		$post_format = get_post_format( $post->ID ); ?>
		<div class="post-body">
			<div class="entry" itemprop="articleBody">
				<?php
					if ( is_single() ) {
						if ($post_format == 'quote') {
							the_content();
						} elseif ($post_format == 'gallery') {
							the_content();
						} elseif ($post_format == 'video') {
							the_excerpt();
						} else {
							the_content();
						}
					} else {
						the_content( sprintf( __( 'Read More', 'charity-wpl' ),  false ) );
					}

				wp_link_pages( array(
					'before'      => '<div class="page-links"><span class="page-links-title">' . __( 'Pages:', 'charity-wpl' ) . '</span>',
					'after'       => '</div>',
					'link_before' => '<span>',
					'link_after'  => '</span>',
					'pagelink'    => '<span class="screen-reader-text">' . __( 'Page', 'charity-wpl' ) . ' </span>%',
					'separator'   => '<span class="screen-reader-text">, </span>',
				) ); ?>
			</div><!-- /.entry -->
		</div><!-- /.post-body -->
	<?php }
endif;
add_action( 'wplook_post_body', 'wplook_get_post_body' );

/*------------------------------------------------------------
	Get Post Body excerpt (for audio aside status quote)
============================================================*/
if ( !function_exists( 'wplook_get_post_body_excerpt' ) ) :
	function wplook_get_post_body_excerpt() {
		global $post;
		$post_format = get_post_format( $post->ID );  ?>
		<div class="post-body">
			<div class="entry" itemprop="articleBody">
				<?php if ( has_excerpt( $post->ID ) ) {
					the_excerpt();
				}
				if (!($post_format == 'quote')) {
					echo '<div class="post-actions"><a class="button small" href="'.esc_url(get_permalink($post->ID)).'">'.__('Read More', 'charity-wpl').'</a></div>';
				}
				wp_link_pages( array(
					'before'      => '<div class="page-links"><span class="page-links-title">' . __( 'Pages:', 'charity-wpl' ) . '</span>',
					'after'       => '</div>',
					'link_before' => '<span>',
					'link_after'  => '</span>',
					'pagelink'    => '<span class="screen-reader-text">' . __( 'Page', 'charity-wpl' ) . ' </span>%',
					'separator'   => '<span class="screen-reader-text">, </span>',
				) ); ?>
			</div><!-- /.entry -->
		</div><!-- /.post-body -->
	<?php }
endif;
add_action( 'wplook_post_body_excerpt', 'wplook_get_post_body_excerpt' );

/*------------------------------------------------------------
	Get Post Category and Tags
============================================================*/
if ( !function_exists( 'wplook_get_post_cat_tag' ) ) :
	function wplook_get_post_cat_tag() { ?>
		<div class="post_tag_category">
			<?php if(ot_get_option('wpl_category_single_post') == "on") : ?>
				<div class="post-category">
					<i class="far fa-folder-open"></i> <?php the_category(', '); ?>
				</div>
			<?php endif; ?>

			<?php if(ot_get_option('wpl_tags_single_post') == "on") : ?>
				<div class="post-tags">
					<?php if ( get_the_tag_list( '', ', ' ) ) { ?>
						<div class="tags"><i class="fas fa-tags"></i> <?php echo get_the_tag_list('',', ',''); ?></div>
					<?php } ?>
				</div><!-- /.post-tags -->
			<?php endif; ?>
		</div>
	<?php }
endif;
add_action( 'wplook_post_cat_tag', 'wplook_get_post_cat_tag' );

/*------------------------------------------------------------
	Get Post Author bio
============================================================*/
if ( !function_exists( 'wplook_get_post_author_bio' ) ) :
	function wplook_get_post_author_bio() { ?>
		<?php if(ot_get_option('wpl_author_bio_single_post') == 'on' && get_the_author_meta( 'description' )) : ?>
			<div class="post-authorbox">
				<div class="post-authorbox-image">
					<a href="<?php echo esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ); ?>" title="<?php the_author(); ?>">
						<?php echo get_avatar(get_the_author_meta( 'ID' ), 155); ?>
					</a>
				</div><!-- /.post-authorbox-image -->

				<div class="post-authorbox-content">
					<h4><?php the_author_meta('display_name'); ?></h4>

					<p><?php the_author_meta('description') ?></p>
				</div><!-- /.post-authorbox-content -->
			</div><!-- /.post-authorbox -->
		<?php endif; ?>
	<?php }
endif;
add_action( 'wplook_post_author_bio', 'wplook_get_post_author_bio' );

/*------------------------------------------------------------
	Get Post share btn
============================================================*/
if ( !function_exists( 'wplook_get_post_share_btn' ) ) :
	function wplook_get_post_share_btn() { ?>
		<?php if(ot_get_option('wpl_share_btn_single_post') == 'on' ) : ?>
			<div class="post-share">
				<div class="socials">
					<span><?php _e('Share it on', 'charity-wpl') ?></span>
					<ul>
						<li class="link-facebook">
							<a title="<?php _e('Share On Facebook', 'charity-wpl'); ?>" class="share-post" data-share-url="http://www.facebook.com/sharer.php?u=<?php the_permalink(); ?>"><i class="fab fa-facebook"></i></a>
						</li>
						<li class="link-twitter">
							<a title="<?php _e('Share On Twitter', 'charity-wpl'); ?>" class="share-post" data-share-url="http://twitter.com/intent/tweet?text=<?php the_title(); ?>&url=<?php the_permalink(); ?>"><i class="fab fa-twitter"></i></a>
						</li>
						<li class="link-googleplus">
							<a title="<?php _e('Share On Google Plus', 'charity-wpl'); ?>" class="share-post" data-share-url="https://plus.google.com/share?url=<?php the_permalink(); ?>"><i class="fab fa-google-plus-g"></i></a>
						</li>
						<li class="link-linkedin">
							<a title="<?php _e('Share On Linkedin', 'charity-wpl'); ?>" class="share-post" data-share-url="https://www.linkedin.com/shareArticle?mini=true&url=<?php the_permalink(); ?>&summary=<?php the_title(); ?>"><i class="fab fa-linkedin-in"></i></a>
						</li>
					</ul>

				</div><!-- /.socials -->
			</div><!-- /.post-share -->
		<?php endif; ?>
	<?php }
endif;
add_action( 'wplook_post_share_btn', 'wplook_get_post_share_btn' );

/*------------------------------------------------------------
	Get User links
============================================================*/
if ( !function_exists( 'wplook_get_user_urls' ) ) :
	function wplook_get_user_urls() { ?>
		<dl class="sub-nav user-nav">
		<?php
			global $post;
			$current_user = wp_get_current_user();
			$current_template = get_page_template_slug( $post->ID );
		?>
			<dt><b><?php echo esc_html($current_user->display_name); ?></b></dt>
			<dd class="<?php if ( $current_template == "template-user-donations.php" ) {echo "active";} ?>"><a href="<?php echo get_permalink( ot_get_option('wpl_donations_link' ) ); ?>"><?php _e('Donations', 'charity-wpl'); ?></a></dd>
			<dd class="<?php if ( $current_template == "template-user-subscriptions.php" ) {echo "active";} ?>"><a href="<?php echo get_permalink( ot_get_option('wpl_subscriptions_link' ) ); ?>"><?php _e('Active Subscriptions', 'charity-wpl'); ?></a></dd>
			<dd><a href="<?php echo wp_logout_url( home_url() ); ?>"><?php _e('Log out', 'charity-wpl'); ?></a></dd>
		</dl>
	<?php }
endif;
add_action( 'wplook_user_urls', 'wplook_get_user_urls' );
