<?php
/**
 * Template modification Hooks
 */
$display_loop_meta = apply_filters( 'maglume_display_loop_meta', true );
do_action( 'maglume_loop_meta', 'start' );

if ( !$display_loop_meta )
	return;

/**
 * If viewing a multi post page 
 */
if ( !is_front_page() && !is_singular() ) :

	$display_title = apply_filters( 'maglume_loop_meta_display_title', true, 'plural' );
	if ( $display_title !== 'hide' ) :

		// Display Featured Image in header if present (static/parallax)
		$pgheadimg = hoot_data( 'pgheadimg' );
		$wrapclasses = is_array( $pgheadimg ) && !empty( $pgheadimg[0] ) && is_string( $pgheadimg[0] ) ? $pgheadimg[0] : '';
		$image =       is_array( $pgheadimg ) && !empty( $pgheadimg[1] ) && is_string( $pgheadimg[1] ) ? $pgheadimg[1] : '';
		hoot_unset_data( 'pgheadimg' );
		?>

		<div <?php hoot_attr( 'loop-meta-wrap', 'archive', $wrapclasses ); ?>>
			<?php echo wp_kses_post( $image ); ?>
			<div class="hgrid">

				<div <?php hoot_attr( 'loop-meta', 'archive', 'hgrid-span-12' ); ?>>

					<?php if ( is_author() ) :
						$author = get_user_by( 'slug', get_query_var( 'author_name' ) );
						if ( $author ) :
							?><div class="loop-meta-gravatar"><?php
								$author = get_user_by( 'slug', get_query_var( 'author_name' ) );
								$gwidth = apply_filters( 'maglume_loop_meta_gravatar', 0 );
								$gwidth = intval( $gwidth );
								$gwidth = ( !empty( $gwidth ) ) ? $gwidth : 150;
								add_filter( 'get_avatar', 'maglume_ns_filter_avatar', 10, 6 );
								echo get_avatar( $author->ID, $gwidth, '404' );
								remove_filter( 'get_avatar', 'maglume_ns_filter_avatar', 10, 6 );
							?></div><?php
						endif;
					endif; ?>

					<h1 <?php hoot_attr( 'loop-title', 'archive' ); ?>><?php echo wp_kses_post( get_the_archive_title() ); // Displays title for archive type (multi post) pages. ?></h1>

					<?php if ( $desc = get_the_archive_description() ) : ?>
						<div <?php hoot_attr( 'loop-description', 'archive' ); ?>>
							<?php echo wp_kses_post( $desc ); // Displays description for archive type (multi post) pages. ?>
						</div><!-- .loop-description -->
					<?php endif; // End paged check. ?>

				</div><!-- .loop-meta -->

			</div>
		</div>

	<?php
	hoot_set_data( 'loop_meta_displayed', true );
	endif;

/**
 * If viewing a single post/page
 */
elseif ( is_singular() ) :

	if ( have_posts() ) :

		// Begins the loop through found posts, and load the post data.
		while ( have_posts() ) : the_post();

			$display_title = apply_filters( 'maglume_loop_meta_display_title', '', 'singular' );
			if ( $display_title !== 'hide' ) :

				// Display Featured Image in header if present (static/parallax)
		$pgheadimg = hoot_data( 'pgheadimg' );
		$wrapclasses = is_array( $pgheadimg ) && !empty( $pgheadimg[0] ) && is_string( $pgheadimg[0] ) ? $pgheadimg[0] : '';
		$image =       is_array( $pgheadimg ) && !empty( $pgheadimg[1] ) && is_string( $pgheadimg[1] ) ? $pgheadimg[1] : '';
		hoot_unset_data( 'pgheadimg' );
				?>

				<div <?php hoot_attr( 'loop-meta-wrap', 'singular', $wrapclasses ); ?>>
					<?php echo wp_kses_post( $image ); ?>
					<div class="hgrid">

						<div <?php hoot_attr( 'loop-meta', 'singular', 'hgrid-span-12' ); ?>>
							<div class="entry-header">

								<?php
								global $post;
								$pretitle = ( !isset( $post->post_parent ) || empty( $post->post_parent ) ) ? '' : '<span class="loop-pretitle">' . get_the_title( $post->post_parent ) . ' &raquo; </span>';
								$pretitle = apply_filters( 'maglume_singular_loop_pretitle', $pretitle );
								?>
								<h1 <?php hoot_attr( 'loop-title' ); ?>><?php the_title( $pretitle ); ?></h1>

								<?php
								$hide_meta_info = apply_filters( 'maglume_hide_meta', false, 'top' );
								if ( !$hide_meta_info ) {

									if ( function_exists( 'is_bbpress' ) && is_bbpress() ):
										if ( bbp_is_single_forum() ) {
											?><div <?php hoot_attr( 'loop-description' ); ?>><?php
												bbp_forum_content();
											?></div><!-- .loop-description --><?php
										};
									elseif (
										!is_attachment() &&
										!( function_exists( 'is_buddypress' ) && is_buddypress() )
									):
										$metarray = is_page() ? hoot_get_mod('page_meta') : hoot_get_mod('post_meta');
										$loc = is_page() ? hoot_get_mod( 'page_meta_location' ) : hoot_get_mod( 'post_meta_location' );
										$has_meta = hoot_meta_info( $metarray, 'loop-meta', true );
										$is_cpreview = is_customize_preview();
										$metarraytop = ( $loc == 'top' && (
											$is_cpreview ||
											$has_meta
										) );
										if ( apply_filters( 'maglume_singular_loopmeta_hascallback', false ) ) {
											do_action( 'maglume_singular_loopmeta_callback', $metarray, $loc, $metarraytop, $has_meta, $is_cpreview );
										} elseif ( $metarraytop ) {
											?><div <?php hoot_attr( 'loop-description' ); ?>><?php
												hoot_display_meta_info( $metarray, 'loop-meta', true, 'entry-byline-metarray' );
											?></div><!-- .loop-description --><?php
										};
									endif;

								}
								?>

							</div><!-- .entry-header -->
						</div><!-- .loop-meta -->

					</div>
				</div>

			<?php
			hoot_set_data( 'loop_meta_displayed', true );
			endif;

		endwhile;
		rewind_posts();

	endif;

endif;

/**
 * Template modification Hooks
 */
do_action( 'maglume_loop_meta', 'end' );