<?php 

  if( ! function_exists( 'anews_site_branding' ) ) :
  /**
     * Site Branding
     *
     * @since 1.0.0
     */
  function anews_site_branding() { ?>
  <div class="site-branding-area">
      <div class="container">
          <div class="row align-items-center">
              <div class="col-12 col-sm-6 col-md-5 col-lg-4 col-xl-4 site-logo">
                  <div class="site-branding">
                      <?php
                    the_custom_logo();
                    if ( is_front_page() && is_home() ) :
                      ?>
                      <h1 class="site-title"><a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></a></h1>
                      <?php
                    else :
                      ?>
                      <h1 class="site-title"><a href="<?php echo esc_url( home_url( '/' ) ); ?>"
                              rel="home"><?php bloginfo( 'name' ); ?></a></h1>
                      <?php
                    endif;
                    $anews_description = get_bloginfo( 'description', 'display' );
                    if ( $anews_description || is_customize_preview() ) :
                      ?>
                      <p class="site-description">
                          <?php echo $anews_description; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
                      </p>
                      <?php endif; ?>
                  </div><!-- .site-branding -->
              </div>
              <div class="col-12 col-sm-6 col-md-7 col-lg-8 col-xl-8 header-banner">
                <?php if(!empty(get_theme_mod( 'anews_tmop_header_select_ads' ))) : ?>
                  <div class="header-advertisement">
                      <?php if( 'link' == get_theme_mod( 'anews_tmop_header_select_ads', true )) { ?>
                      <a href="<?php echo esc_url(get_theme_mod( 'anews_tmop_header_ads_link' )); ?>">
                          <img src="<?php echo esc_url(get_theme_mod('anews_tmop_header_ads_img','')); ?>"
                              alt="<?php esc_attr_e('anews Banner','anews') ?>">
                      </a>
                      <?php } else {
                      echo get_theme_mod('anews_tmop_header_ads_code');
                    } 
                    ?>
                  </div>
                  <?php endif; ?>
              </div>
          </div>
      </div>
  </div>
  <nav id="site-navigation" class="main-navigation navbar-area navbar navbar-expand-lg navbar-light" role="navigation">
      <div class="container">
          <div class="navbar-collapse nav-menu">
            <div id="mobile"></div>
              <?php
                wp_nav_menu(
                  array(
                    'container' 		  => false,
                    'theme_location' 	=> 'primary_menu',
                    'menu_id'        	=> 'primary-menu',
                    'menu_class'      => 'sf-menu',
                    'fallback_cb'     => 'anews_primary_navigation_fallback',
                  )
                );
                ?>
        </div>
        <?php if( true == get_theme_mod( 'anews_tmop_header_date_show', false ) ) : ?>
        <div class="header-date"><i class="fas fa-calendar-alt"></i><?php echo esc_html(date("j F, Y"));  ?></div>
        <?php endif; ?>
        <?php if( true == get_theme_mod( 'anews_tmop_header_search_show', false ) ) : ?>
        <div class="header-search">
            <form method="get" class="search-form" action="<?php echo esc_url( home_url( '/' ) ); ?>">
                <input type="search" class="search-field" placeholder="<?php esc_attr_e( 'Search ', 'anews' ) ?>"
                    value="<?php echo esc_attr(get_search_query()) ?>" name="s"
                    title="<?php esc_attr_e( 'Search for:', 'anews' ) ?>" />
                <div class="search-button">
                    <button type="submit" class="search-submit"><span class="fas fa-search"></span></button>
                </div>
            </form>
        </div>
        <?php endif; ?>
    </div>
  </nav><!-- #site-navigation -->
<?php }
  endif;
  add_action( 'anews_action_header', 'anews_site_branding', 10 );

  if ( ! function_exists( 'anews_footer_top_section' ) ) :

    /**
     * Top  Footer 
     *
     * @since 1.0.0
     */
    function anews_footer_top_section() { 
        $anews_fttops = get_theme_mod( 'anews_footer_tops' );
        if(!empty($anews_fttops)) :
        ?>
        <div class="footer-top">
            <div class="row">
                <?php foreach( $anews_fttops as $anews_fttop ) : 
                $anews_ftimg = wp_get_attachment_image_src( $anews_fttop['anews_footer_top_img'], 'full' );
                ?>
                <div class="col-12 col-sm-6 col-md-4 col-lg-2">
                    <div class="footer-top-item">
                        <img src="<?php echo esc_url($anews_ftimg[0]); ?>" alt="<?php esc_attr('anews Footer Instragram','anews'); ?>">
                        <a href="<?php echo esc_url( $anews_fttop['anews_footer_top_url'] ); ?>"><i class="fab fa-instagram"></i></a>
                    </div>
                </div>
                <?php endforeach; ?>
            </div>
        </div>
      <?php endif;
   }
  endif;
  add_action( 'anews_action_footer', 'anews_footer_top_section', 10 );  
 
  if ( ! function_exists( 'anews_footer_widgets' ) ) :
    function anews_footer_widgets() { ?>
      <?php 
      $footer_col = '3_3_3_3';
        if( !empty($footer_col) ){
          $footer_col = '3_3_3_3';
        }
        $footer_start	= '';
        $footer_end		= '';
        if ( is_active_sidebar( 'footer-1' ) || is_active_sidebar( 'footer-2' ) || is_active_sidebar( 'footer-3' ) || is_active_sidebar( 'footer-4' )) 
        {
          $footer_start='<div class="footer-widgets-area">';
          $footer_end='</div>';
        }	
        echo wp_kses($footer_start,'anews_allowed_html');
        if ( is_active_sidebar( 'footer-1' ) || is_active_sidebar( 'footer-2' ) || is_active_sidebar( 'footer-3' ) || is_active_sidebar( 'footer-4' ) ) 
        {
            ?>
            <?php 
            if($footer_col == '3_3_3_3'){
            ?>
            <div class="row anews-ftw-box">
                <?php if ( is_active_sidebar( 'footer-1' ) ) : ?>
                    <div class="col-xs-12 col-sm-12 col-md-6 col-lg-6 col-xl-3">
                        <?php dynamic_sidebar( 'footer-1' ); ?>
                    </div><!-- .widget-area -->
                <?php endif; ?>
                <?php if ( is_active_sidebar( 'footer-2' ) ) : ?>
                    <div class="col-xs-12 col-sm-12 col-md-6 col-lg-6 col-xl-3">
                        <?php dynamic_sidebar( 'footer-2' ); ?>
                    </div><!-- .widget-area -->
                <?php endif; ?>	
                <?php if ( is_active_sidebar( 'footer-3' ) ) : ?>
                    <div class="col-xs-12 col-sm-12 col-md-6 col-lg-6 col-xl-3">
                        <?php dynamic_sidebar( 'footer-3' ); ?>
                    </div><!-- .widget-area -->
                <?php endif; ?>
                <?php if ( is_active_sidebar( 'footer-4' ) ) : ?>
                    <div class="col-xs-12 col-sm-12 col-md-6 col-lg-6 col-xl-3">
                        <?php dynamic_sidebar( 'footer-4' ); ?>
                    </div><!-- .widget-area -->
                <?php endif; ?>
            </div>
            <?php }else{ ?>
                <div class="row anews-ftw-box">
                    <?php
                    $footer_col = explode('_', $footer_col);
                    
                    if( is_array($footer_col) && count($footer_col)>0 ){
                        $i = 1;
                        foreach($footer_col as $col){
                        // ROW width class
                        $row_class = 'col-xs-12 col-sm-12 col-md-6 col-lg-6 col-xl-'.$col;
                        if ( is_active_sidebar( 'footer-'.$i.'' ) ) : ?>
                            <div class="widget-area <?php echo esc_attr($row_class); ?> footer">
                                <?php dynamic_sidebar( 'footer-'.$i.'' ); ?>
                            </div><!-- .widget-area -->
                        <?php endif;
                        $i++;
                        }
                    }
                    ?>
                </div>
            <?php } ?>
          <?php
        }
        echo wp_kses($footer_end,'anews_allowed_html'); ?>
    <?php  }
  endif;
  add_action( 'anews_action_footer', 'anews_footer_widgets', 10 );

  if ( ! function_exists( 'anews_footer_site_info' ) ) :
    function anews_footer_site_info() { ?>
      <div class="site-info copyright-area">
        <?php
          $anews_copyright_footer = get_theme_mod('anews_copyright_text'); 
          if ( ! empty( $anews_copyright_footer ) ) {
            $anews_copyright_footer = wp_kses_post( $anews_copyright_footer );
          }
          /* translators: %s: powered by */
          $anews_powered_by = sprintf( esc_html__( ' Theme Anews by %s', 'anews' ), '<a target="_blank" rel="dofollow" href="'. esc_url( 'https://themeuniver.com/' ) .'">themeuniver</a> <a target="_blank" rel="dofollow" href="'. esc_url( 'https://www.allvideodownloade.com/' ) .'">Support Allvideodownloade</a>' );
        ?>
      <?php echo esc_html($anews_copyright_footer);?><?php echo wp_kses_post( $anews_powered_by );?>
    </div>
  <?php  }
  endif;
  add_action( 'anews_action_footer', 'anews_footer_site_info', 10 );  
  

  if ( ! function_exists( 'anews_reslted_post_start' ) ) :
    function anews_reslted_post_start() { ?>
      <div class="related-post-section">
      <h3 class="related-title comment-reply-title"><?php esc_html_e('Related Post','anews'); ?></h3>
      <div class="row">
  <?php  }
  endif;
  add_action( 'anews_action_before_realted_post', 'anews_reslted_post_start', 10 );
  
  if ( ! function_exists( 'anews_action_realted_post_item' ) ) :
    function anews_action_realted_post_item() { 
      if( 'center' != get_theme_mod( 'anews_single_layout', 'right' ) &&  is_active_sidebar( 'sidebar-1' )){
        $anews_items = 3;
        $anews_class = 'col-lg-4';
      }else{
        $anews_items = 4;
        $anews_class = 'col-lg-3';
      }


      $anews_related_texonomy = wp_get_object_terms( get_the_ID(), 'category', array('fields' => 'ids') );
      //query arguments
      $args = array(
        'post_type' => 'post',
        'post_status' => 'publish',
        'posts_per_page' => 3,
        'orderby' => 'rand',
        'tax_query' => array(
          array(
            'taxonomy' => 'category',
            'field' => 'id',
            'terms' => $anews_related_texonomy
          )
        ),
        'post__not_in' => array (get_the_ID()),
      );
      //the query
      $anews_PrelatedPosts = new WP_Query( $args );
      if($anews_PrelatedPosts->have_posts()) :
        while($anews_PrelatedPosts->have_posts()) : $anews_PrelatedPosts->the_post(); 
    ?>
    
      <div class="col-12 col-sm-12-col-md-6 <?php echo esc_attr($anews_class); ?> small-list color4">
        <div class="anews-category-post-items">
          <div class="anews-hpost-item">
            <?php if(has_post_thumbnail()) : ?>
            <div class="hpost-img">
                <a href="<?php echo esc_url(the_permalink()); ?>">
                    <?php the_post_thumbnail('full', array('class' => 'img-responsive')); ?>
                </a>
            </div>
            <?php endif; ?>
            <div class="hpost-contents">
                <div class="anews-home-post-meta">
                    <ul>
                        <?php anews_post_cat(); ?>
                    </ul>
                </div>
                <h2><a href="<?php echo esc_url(the_permalink()); ?>"><?php the_title(); ?></a></h2>
                <span><?php esc_html_e('By','anews'); ?>
                  <?php echo esc_html(get_the_author()); ?></span>
            </div>
          </div>
        </div>
      </div>
  <?php endwhile; wp_reset_query(); endif; }
  endif;
  add_action( 'anews_action_realted_post', 'anews_action_realted_post_item', 10 );


  if ( ! function_exists( 'anews_reslted_post_end' ) ) :
    function anews_reslted_post_end() { ?>
      </div>
      </div>
  <?php  }
  endif;
  add_action( 'anews_action_after_realted_post', 'anews_reslted_post_end', 10 );

if ( ! function_exists( 'anews_single_ads3_banner' ) ) :
  function anews_single_ads3_banner() { ?>
    <?php if( true == get_theme_mod( 'anews_single_ads3_enalbe', false )) : ?>
  <div class="anews-post-single-ads-section pt-5 pb-3">
    <div class="anews-post-ads-inner">
    <?php if( 'link' == get_theme_mod( 'anews_single_ads3_select', true )) { ?>
    <a href="<?php echo esc_url(get_theme_mod( 'anews_single_ads3_link' )); ?>">
      <img src="<?php echo esc_url(get_theme_mod('anews_single_ads3_img','')); ?>" alt="<?php esc_attr_e('anews Banner','anews') ?>">
    </a>
    <?php } else {
      echo get_theme_mod('anews_single_ads3_code');
    } 
    ?>
    </div>
  </div>
  <?php endif; ?>
<?php  }
endif;
add_action( 'anews_single_ads3', 'anews_single_ads3_banner', 10 );

if ( ! function_exists( 'anews_single_ads1_banner' ) ) :
  function anews_single_ads1_banner() { ?>
    <?php if( true == get_theme_mod( 'anews_single_ads1_enalbe', false )) : ?>
  <div class="anews-post-single-ads-section pt-3 pb-5">
    <div class="anews-post-ads-inner">
    <?php if( 'link' == get_theme_mod( 'anews_single_ads1_select', true )) { ?>
    <a href="<?php echo esc_url(get_theme_mod( 'anews_single_ads1_link' )); ?>">
      <img src="<?php echo esc_url(get_theme_mod('anews_single_ads1_img','')); ?>" alt="<?php esc_attr_e('anews Banner','anews') ?>">
    </a>
    <?php } else {
      echo get_theme_mod('anews_single_ads1_code');
    } 
    ?>
    </div>
  </div>
  <?php endif; ?>
<?php  }
endif;
add_action( 'anews_single_ads1', 'anews_single_ads1_banner', 10 );

if ( ! function_exists( 'anews_single_ads2_banner' ) ) :
  function anews_single_ads2_banner() { ?>
    <?php if( true == get_theme_mod( 'anews_single_ads2_enalbe', false )) : ?>
  <div class="anews-post-single-ads-section pt-3 pb-3">
    <div class="anews-post-ads-inner">
    <?php if( 'link' == get_theme_mod( 'anews_single_ads2_select', true )) { ?>
    <a href="<?php echo esc_url(get_theme_mod( 'anews_single_ads2_link' )); ?>">
      <img src="<?php echo esc_url(get_theme_mod('anews_single_ads2_img','')); ?>" alt="<?php esc_attr_e('anews Banner','anews') ?>">
    </a>
    <?php } else {
      echo get_theme_mod('anews_single_ads2_code');
    } 
    ?>
    </div>
  </div>
  <?php endif; ?>
<?php  }
endif;
add_action( 'anews_single_ads2', 'anews_single_ads2_banner', 10 );

if ( ! function_exists( 'anews_braking_news_items' ) ) :
  function anews_braking_news_items() { ?>
  <?php if( true == get_theme_mod( 'anews_teop_news_ticker_show' )) : ?>
    <div class="braking-news-slide">
      <?php 
      $p = new \WP_Query( array( 
        'posts_per_page' => 5,
        'post_type' => 'post', 
      )); ?>
      <div class="container">
        <div class="braking-inner">
          <div class="braking-title">
          <span><i class="fas fa-transgender-alt"></i><?php echo esc_html(get_theme_mod( 'anews_teop_news_ticker_tile','Trending News:' )); ?></span>
          </div>
          <div class="braking-sldes">
            <ul class="braking owl-carousel owl-theme">
            <?php  while ( $p->have_posts() ): $p->the_post(); ?>
              <li><a href="<?php echo esc_url(the_permalink()); ?>"><?php the_title(); ?></a></li>
            <?php endwhile; wp_reset_query(); ?>
            </ul>
          </div>
        </div>
      </div>
    </div>
<?php endif;  }
endif;
add_action( 'anews_braking_news', 'anews_braking_news_items', 10 );

// demo import 

function anews_ocdi_import_files() {
  $url = 'https://deta.themeuniver.com/anews/';
  $demo = 'https://free.themeuniver.com/anews';
  return array(
	  	array(
		  	'import_file_name'  => esc_html__('Demo page','anews' ),
		  	'import_file_url' =>  $url . 'demo.xml',
		  	'import_widget_file_url'  => $url . 'widgets.wie',
		  	'import_customizer_file_url'  => $url . 'customizer.dat',
			'preview_url'   => $demo,
	 	),
	);
}
add_filter( 'ocdi/import_files', 'anews_ocdi_import_files' );
function ocdi_after_import_setup() {
    // Assign menus to their locations.
    $main_menu = get_term_by( 'name', 'Main Menu', 'nav_menu' );
    $top_menu = get_term_by( 'name', 'Header Top', 'nav_menu' );
    set_theme_mod( 'nav_menu_locations', array(
            'primary_menu' => $main_menu->term_id, // replace 'main-menu' here with the menu location identifier from register_nav_menu() function
            'header_top_menu' => $top_menu->term_id, // replace 'main-menu' here with the menu location identifier from register_nav_menu() function
        )
    );
    // Assign front page and posts page (blog page).
    $front_page_id = get_page_by_title( 'Home' );
    $blog_page_id  = get_page_by_title( 'Blog' );

    update_option( 'show_on_front', 'page' );
    update_option( 'page_on_front', $front_page_id->ID );
    update_option( 'page_for_posts', $blog_page_id->ID );

}
add_action( 'ocdi/after_import', 'ocdi_after_import_setup' );
