<?php
/**
 * Return url with Google Fonts.
 *
 * @return string Google fonts URL for the theme.
 */
function tribute_google_web_fonts_url() {
	$fonts_url = '';
	$fonts     = array();
	$subsets   = array( 'latin', 'latin-ext' );
	$fonts = apply_filters( 'pre_google_web_fonts', $fonts );
	foreach ( $fonts as $key => $value ) {
		$fonts[ $key ] = $key . ':' . implode( ',', $value );
	}
	/* translators: To add an additional character subset specific to your language, translate this to 'greek', 'cyrillic', 'devanagari' or 'vietnamese'. Do not translate into your own language. */
	$subset = _x( 'no-subset', 'Add new subset (greek, cyrillic, devanagari, vietnamese)', 'tribute');
	if ( 'cyrillic' == $subset ) {
		array_push( $subsets, 'cyrillic', 'cyrillic-ext' );
	} elseif ( 'greek' == $subset ) {
		array_push( $subsets, 'greek', 'greek-ext' );
	} elseif ( 'devanagari' == $subset ) {
		array_push( $subsets, 'devanagari' );
	} elseif ( 'vietnamese' == $subset ) {
		array_push( $subsets, 'vietnamese' );
	}
	$subsets = apply_filters( 'subsets_google_web_fonts', $subsets );
	if ( $fonts ) {
		$fonts_url = add_query_arg(
			array(
				'family' => urlencode( implode( '|', $fonts ) ),
				'subset' => urlencode( implode( ',', array_unique( $subsets ) ) ),
			),
			'//fonts.googleapis.com/css'
		);
	}
	return apply_filters( 'google_web_fonts_url', $fonts_url );
}
/**
 * Return Google fonts and sizes
 *
 * @return array Google fonts and sizes.
 */
function tribute_additional_fonts( $fonts ) {
	/* translators: If there are characters in your language that are not supported by Noto Serif, translate this to 'off'. Do not translate into your own language. */
	if ( 'off' !== _x( 'on', 'Open Sans font: on or off', 'tribute' ) ) {
		$fonts['Open Sans'] = array('300italic' => '300italic','400italic'=>'400italic','600italic'=>'600italic','700italic'=>'700italic','800italic'=>'800italic','400'       => '400','300'=> '300','600'=> '600','700'=> '700','800'=> '800');
	}if ( 'off' !== _x( 'on', 'Oswald font: on or off', 'tribute')){
		$fonts['Oswald'] = array('400'=>'400','300'=> '300','700'=>'700');
	}if ( 'off' !== _x( 'on', 'Great Vibes font: on or off', 'tribute')){
		$fonts['Great Vibes'] = array();
	}
	return $fonts;
}
add_filter('pre_google_web_fonts', 'tribute_additional_fonts');



// Register Tribute script and css 

function tribute_scripts() {
	     wp_enqueue_script('flexslider_jquery', get_template_directory_uri() .'/js/flexslider.min.js', array('jquery'),true );
		 wp_enqueue_script('bootstrap', get_template_directory_uri() .'/js/bootstrap.js', array('jquery'),true );
         wp_enqueue_script('wow_min_js', get_template_directory_uri() . '/js/wow.min.js', array('jquery'),true );
		 wp_enqueue_script('jquery_custom', get_template_directory_uri() . '/js/custom.js', array('jquery'),'',true);
		 wp_localize_script( 'jquery_custom', 'tribute_wp_ajax_url', admin_url( 'admin-ajax.php' ) );  
         wp_enqueue_style('bootstrap_min', get_template_directory_uri() . '/css/bootstrap.min.css' );
         wp_enqueue_style('style', get_stylesheet_uri());
         wp_enqueue_style('responsive_css', get_template_directory_uri() . '/css/responsive.css' );
	     wp_enqueue_style('flexslider_css', get_template_directory_uri() . '/css/flexslider.css' );
	     wp_enqueue_style('font_awesome', get_template_directory_uri() . '/css/font-awesome.min.css' );
         wp_enqueue_style('animate_min', get_template_directory_uri() . '/css/animate.min.css');
         wp_enqueue_style('animate_min', get_template_directory_uri() . '/rtl.css');
		// Load the HTML5 Shiv.
		wp_enqueue_script('tribute-html5', get_template_directory_uri() . '/js/html5shiv.min.js', array(), '3.7.2' );
	    wp_script_add_data( 'tribute-html5', 'conditional', 'lt IE 9' );
        //Respond.js for IE8 support of HTML5 elements and media queries
        wp_enqueue_script('tribute-ie8supportofhtml5', get_template_directory_uri() . '/js/respond.min.js', array(), '1.4.2' );
        wp_script_add_data('tribute-ie8supportofhtml5', 'conditional', 'lt IE 8');
        wp_enqueue_style('tribute-google-fonts', tribute_google_web_fonts_url(), array(), null, 'all' );
}
add_action('wp_enqueue_scripts', 'tribute_scripts');

/**
 * Registers a widget area.
 *
 * @link https://developer.wordpress.org/reference/functions/register_sidebar/
 *
 * @since Tribute
 */

function tribute_widgets_init() {
register_sidebar( array(
	  'name'          => __( 'Widget Area', 'tribute' ),
	  'id'            => 'sidebar-one',
	  'description'   => __( 'Add widgets here to appear in your sidebar.', 'tribute' ),
	  'before_widget' => '<section id="%1$s" class="widget wow fadeInUp %2$s">',
	  'after_widget'  => '</section>',
	  'before_title'  => '<h2 class="widget-title">',
	  'after_title'   => '</h2>',
) );
}

add_action( 'widgets_init', 'tribute_widgets_init');
require get_template_directory() . '/admin/template-tags.php';
require get_template_directory() . '/admin/tributepro/class-customize.php';
require get_template_directory() . '/admin/customizer.php';
require get_template_directory() . '/admin/custom_header.php';
require get_template_directory() . '/admin/custom_css.php';
function tribute_editor_styles() {

    add_editor_style( 'editor-style.css');

}

add_action('admin_init', 'tribute_editor_styles' );
add_filter('comments_open', 'tribute_comments_open', 10, 2 );
function tribute_comments_open( $open, $post_id ) {
	$post = get_post( $post_id );
    if (get_post_meta($post->ID, 'Allow Comments', true)) {$open = true;}
	return $open;
}

/* takes user input from the customizer and outputs linked social media icons */
function tribute_social_media_icons() {
    $social_sites = tribute_customizer_social_media_array();
    /* any inputs that aren't empty are stored in $active_sites array */
    foreach($social_sites as $social_site) {
        if( strlen( get_theme_mod( $social_site ) ) > 0 ) {
            $active_sites[] = $social_site;
        }
    }
    /* for each active social site, add it as a list item */
        if ( ! empty( $active_sites ) ) {
            echo "<div class='social-media-icons social'>";
            foreach ( $active_sites as $active_site ) {
	            /* setup the class */
		        $class = 'fa fa-' . $active_site;
                if ( $active_site == 'email' ) {
                    ?>
                         <a class="email" target="_blank" href="mailto:<?php echo antispambot(is_email( get_theme_mod( $active_site ) ) ); ?>">
                            <i class="fa fa-envelope" title="<?php _e('email icon', 'tribute'); ?>"></i>
                        </a>
                 <?php } else { ?>
                         <a class="<?php echo $active_site; ?>" target="_blank" href="<?php echo esc_url( get_theme_mod( $active_site) ); ?>">
                            <i class="<?php echo esc_attr( $class ); ?>" title="<?php printf( __('%s icon', 'tribute'), $active_site ); ?>"></i>
                        </a>
                 <?php
                }
            }
            echo "</div>";
        }

}
function tribute_load_more_posts()
{
	$the_query = new WP_Query( array('posts_per_page' =>3,'paged'=>$_POST['paged'] ) );
		while($the_query->have_posts()) : $the_query->the_post();?>
		 <?php
/**
 * The default template for displaying content
 *
 * Used for both single and index/archive/search.
 *
 * @package WordPress
 * @subpackage Tribute
 * @since Tribute 1.0
 */
?>
<div <?php post_class(); ?> id="post-<?php the_ID(); ?>">
  <header class="entry-header wow fadeInUp">
<h2 class="entry-title"><?php tribute_post_title(); ?></h2>
    <div class="entry-meta">
      <?php the_time('F j, Y') ?>
     <?php printf(__('by', 'tribute' )); ?> 
      <?php the_author_posts_link() ?>
      <?php printf(__('|', 'tribute' )); ?> 
      <?php comments_number(__('No Comments','tribute'), __('One Comment', 'tribute'), __('% Comments', 'tribute') );?>
    </div>
    
    <!--entry-meta--> 
    
  </header>
  <div class="entry-summary wow fadeInUp">
    <?php tribute_post_thumbnail(); ?>
    <?php if ( is_single() ) : ?>
     <?php the_content(); else: ?>
      <p><?php the_excerpt(); ?></p>
      <p><?php echo '<a class="btn btn-default" href="' . esc_url(get_permalink()). '">' . __('Continue Reading', 'tribute') . '</a>'; ?> </p>
    <?php endif; ?>
    <?php wp_link_pages( array( 'before' => '<p class="page-links">' . '<span class="before">' . __( 'Pages:', 'tribute' ) . '</span>', 'after' => '</p>' ) );?>	
  </div>
  
  <!--entry-summary--> 
  
  <div class="entry-footer">
  <div class="entry-meta">
 <span class="Posted"> <?php printf(__('Posted in:', 'tribute' )); ?> </span><?php the_category();?> <div class="tag"><?php the_tags();?></div>
  
</div></div>
  
</div>
<!--entry--> 

		<?php endwhile;
	die; // here we exit the script and even no wp_reset_query() required!
}
add_action( 'wp_ajax_tribute_load_more_posts', 'tribute_load_more_posts');
add_action( 'wp_ajax_nopriv_tribute_load_more_posts', 'tribute_load_more_posts');
//
function tribute_load_more_posts_grid()
{
	$grid=1;
	$the_query = new WP_Query( array('posts_per_page' =>4,'paged'=>$_POST['paged'] ) );
		while($the_query->have_posts()) : $the_query->the_post();?>
		 <?php
/**
 * The default template for displaying content
 *
 * Used for both single and index/archive/search.
 *
 * @package WordPress
 * @subpackage Tribute
 * @since Tribute 1.0
 */
?>
<aside class="col-md-6 col-sm-6 col-xs-12">
<div <?php post_class(); ?> id="post-<?php the_ID(); ?>">
  <header class="entry-header wow fadeInUp">
<h2 class="entry-title"><?php tribute_post_title(); ?></h2>
    <div class="entry-meta">
      <?php the_time('F j, Y') ?>
     <?php printf(__('by', 'tribute' )); ?> 
      <?php the_author_posts_link() ?>
      <?php printf(__('|', 'tribute' )); ?> 
      <?php comments_number(__('No Comments','tribute'), __('One Comment', 'tribute'), __('% Comments', 'tribute') );?>
    </div>
    
    <!--entry-meta--> 
    
  </header>
  <div class="entry-summary wow fadeInUp">
    <?php tribute_post_thumbnail(); ?>
    <?php if ( is_single() ) : ?>
     <?php the_content(); else: ?>
      <p><?php the_excerpt(); ?></p>
      <p><?php echo '<a class="btn btn-default" href="' . esc_url(get_permalink()). '">' . __('Continue Reading', 'tribute') . '</a>'; ?> </p>
    <?php endif; ?>
    <?php wp_link_pages( array( 'before' => '<p class="page-links">' . '<span class="before">' . __( 'Pages:', 'tribute' ) . '</span>', 'after' => '</p>' ) );?>	
  </div>
  
  <!--entry-summary--> 
  
  <div class="entry-footer">
  <div class="entry-meta">
 <span class="Posted"> <?php printf(__('Posted in:', 'tribute' )); ?> </span><?php the_category();?> <div class="tag"><?php the_tags();?></div>
  
</div></div>
  
</div>
</aside>
<!--entry--> 
<?php 
if($grid++%2==0)
		{
			echo'<div class="clearfix"></div>';
		}
?>
		<?php endwhile;
	die; // here we exit the script and even no wp_reset_query() required!
}
add_action( 'wp_ajax_tribute_load_more_posts_grid', 'tribute_load_more_posts_grid');
add_action( 'wp_ajax_nopriv_tribute_load_more_posts_grid', 'tribute_load_more_posts_grid');
?>