<?php
/**
 * The template for displaying the footer
 *
 * Contains the closing of the #content div and all content after.
 *
 * @link https://developer.wordpress.org/themes/basics/template-files/#template-partials
 *
 * @package Ostrich Magazine
 */

$default = ostrich_magazine_get_default_mods();
?>

	</div><!-- #content -->

	<footer id="colophon" class="site-footer" role="contentinfo">
		<?php  
		$count = 0;
		for ( $i=1; $i <=4 ; $i++ ) { 
			if ( is_active_sidebar( 'footer-' . $i ) ) {
				$count++;
			}
		}
		
		if ( 0 !== $count ) : ?>
			<div class="footer-widgets-area page-section col-<?php echo esc_attr( $count );?>">
			    <div class="container">
					<?php 
					for ( $j=1; $j <=4; $j++ ) { 
						if ( is_active_sidebar( 'footer-' . $j ) ) {
			    			echo '<div class="hentry">';
							dynamic_sidebar( 'footer-' . $j ); 
			    			echo '</div>';
						}
					}
					?>
				</div><!-- .wrapper -->
			</div><!-- .footer-widget-area -->

		<?php endif; ?>
		 <div class="footer-logo-wrapper col-2 clear">
                <div class="container">
                <article>
                    <div class="footer-logo">
                        <a href="<?php echo esc_url( home_url( '/' ) ); ?>" ><img src="<?php echo esc_url( get_theme_mod( 'ostrich_magazine_footer_logo', '' ) ); ?>"></a>
                    </div>
                </article>

                <article>
                    <aside class="widget widget_social_icons">
                        <?php  
                        	wp_nav_menu(  array(
	                            'theme_location' => 'social',
	                            'container' => 'div',
	                            'container_class' => 'social-icons',
	                            'echo' => true,
	                            'depth' => 1,
	                            'link_before' => '<span class="screen-reader-text">',
	                            'link_after' => '</span>',
	                            'fallback_cb' => false,
	                        ) );
                        ?>
                    </aside>
                </article>
                </div>
            </div>
		<?php $ostrich_magazine_search = array( '[the-year]', '[site-link]' );

        $replace = array( date( 'Y' ), '<a href="'. esc_url( home_url( '/' ) ) .'">'. esc_attr( get_bloginfo( 'name', 'display' ) ) . '</a>' );

        $copyright = str_replace( $ostrich_magazine_search, $replace, get_theme_mod( 'ostrich_magazine_copyright_txt', $default['ostrich_magazine_copyright_txt'] ) );

			?>

		<div class="site-info col-2">
            <div class="container">
        		<span>	<?php echo wp_kses_post(  $copyright ); ?>
				<?php echo wp_kses_post(  $default['ostrich_magazine_power_by_txt']  ); ?>	</span>

                <span>
                    <?php 
					if ( get_theme_mod( 'ostrich_magazine_footer_menu', false )) {
						if ( has_nav_menu( 'footer-menu' ) ) :

							wp_nav_menu( array(
								'theme_location' => 'footer-menu',
								'container' => 'ul',
								'menu_class' => '',
								'menu_id' => '',
							) );
						endif;
					}
					?>
                </span>
            </div><!-- .wrapper -->     
        </div><!-- .site-info -->
	</footer><!-- #colophon -->
	
	<?php  
	$backtop = get_theme_mod( 'ostrich_magazine_back_to_top_enable', true );
	if ( $backtop ) { ?>
		<div class="backtotop"><?php echo ostrich_magazine_get_svg( array( 'icon' => 'up-arrow' ) ); ?></div>
	<?php }	?>
</div><!-- #page -->

<?php wp_footer(); ?>

</body>
</html>
