<?php

/**
 * munix functions and definitions
  @package munix
 *
*/

/* Set the content width in pixels, based on the theme's design and stylesheet.
*/
function munix_content_width() {
	$GLOBALS['content_width'] = apply_filters( 'munix_content_width', 980 );
}
add_action( 'after_setup_theme', 'munix_content_width', 0 );


if( ! function_exists( 'munix_theme_setup' ) ) {	
	
	function munix_theme_setup() {
		load_theme_textdomain( 'munix', get_template_directory() . '/languages' );
		
		// Add default posts and comments RSS feed links to head.
		add_theme_support( 'automatic-feed-links' );
		
		// Add title tag 
		add_theme_support( 'title-tag' );
		
		// Add default logo support		
        add_theme_support( 'custom-logo');

        add_theme_support('post-thumbnails');
        add_image_size('munix-page-thumbnail',738,423, true);
        add_image_size('munix-about-thumbnail',800,550, true);
        add_image_size('munix-blog-front-thumbnail',370,225, true);
        add_image_size('munix-portfolio-thumbnail',900,810, true);
        add_image_size('munix-slider-thumbnail',1350,600, true);
        
        
		
         // Add theme support for Semantic Markup
		add_theme_support( 'html5', array(
			'search-form',
			'comment-form',
			'comment-list',
			'gallery',
			'caption'
		) ); 

		$defaults = array(
			'default-image'          => get_template_directory_uri() .'/styling/img/header.jpg',
			'width'                  => 1920,
			'height'                 => 600,
			'uploads'                => true,
		);
		add_theme_support( 'custom-header', $defaults );

		// Menus
		register_nav_menus(array(
			'primary' => esc_html__('Primary Menu', 'munix'),
		));
		// add excerpt support for pages
        add_post_type_support( 'page', 'excerpt' );
		
        if ( is_singular() && comments_open() ) {
			wp_enqueue_script( 'comment-reply' );
        }
		// Add theme support for selective refresh for widgets.
        add_theme_support( 'customize-selective-refresh-widgets' );
		
		// Custom Backgrounds
   		add_theme_support( 'custom-background', array(
  			'default-color' => 'ffffff',
    	) );

    	// To use additional css
 	    add_editor_style( 'styling/css/editor-style.css' );
	}
	add_action( 'after_setup_theme', 'munix_theme_setup' );
}

   // Register Nav Walker class_alias
    require get_template_directory(). '/class-wp-bootstrap-navwalker.php';
    require get_template_directory(). '/extras.php';
   /**

    * Enqueue CSS stylesheets
    */		
if( ! function_exists( 'munix_enqueue_styles' ) ) {
	function munix_enqueue_styles() {	
	
	    wp_enqueue_style('munix-font', 'https://fonts.googleapis.com/css?family=Josefin+Sans:300,400,600,700|Open+Sans:300,400,600,700','');
		wp_enqueue_style('bootstrap', get_template_directory_uri() . '/styling/css/bootstrap.css','');
		wp_enqueue_style('font-awesome', get_template_directory_uri() .'/styling/css/font-awesome.css','');
		wp_enqueue_style('owl-carousel', get_template_directory_uri() .'/styling/css/owl.carousel.css','');
		wp_enqueue_style('owl-theme', get_template_directory_uri() .'/styling/css/owl.theme.default.css','');
		wp_enqueue_style('slicknav', get_template_directory_uri() .'/styling/css/slicknav.css','');
	
		wp_enqueue_style('smoothbox', get_template_directory_uri() .'/styling/css/smoothbox.css','');

        // main style
		wp_enqueue_style( 'munix-style', get_stylesheet_uri() );
		
			wp_enqueue_style('responsive', get_template_directory_uri() .'/styling/css/responsive.css','');
	}
	add_action( 'wp_enqueue_scripts', 'munix_enqueue_styles' );
}

/**
 * Enqueue JS scripts
 */

if( ! function_exists( 'munix_enqueue_scripts' ) ) {
	function munix_enqueue_scripts() {   
		wp_enqueue_script('jquery');
		wp_enqueue_script('bootstrap', get_template_directory_uri() . '/styling/js/bootstrap.js',array(),'', true);
		wp_enqueue_script('owl-carousel', get_template_directory_uri() . '/styling/js/owl.carousel.js',array(),'', true);
		wp_enqueue_script('slicknav', get_template_directory_uri() . '/styling/js/jquery.slicknav.js',array(),'', true);
		wp_enqueue_script('smoothbox', get_template_directory_uri() . '/styling/js/smoothbox.jquery2.js',array(),'', true);
		wp_enqueue_script('custom', get_template_directory_uri() . '/styling/js/custom.js',array(),'', true);
		
		
	}
	add_action( 'wp_enqueue_scripts', 'munix_enqueue_scripts' );
}


    function munix_cat_count_span($links) {
        $links = str_replace('</a> (', ' <span>', $links);
        $links = str_replace(')', '</span></a>', $links);
        return $links;
    }
    add_filter('wp_list_categories', 'munix_cat_count_span');


    function munix_style_the_archive_count($links) {
        $links = str_replace('</a>&nbsp;(', ' <span class="archiveCount">', $links);
        $links = str_replace(')', '</span></a>', $links);
        return $links;
    }

    add_filter('get_archives_link', 'munix_style_the_archive_count');


    //post excerpt
    function munix_theme_excerpt_global_length( $length ) {
	   return 30;
    }

    function munix_theme_excerpt(){
	    add_filter( 'excerpt_length', 'munix_theme_excerpt_global_length', 999 );
	    echo get_the_excerpt();
    }

    function new_excerpt_more( $more ) {
        return '...';
    }

   add_filter('excerpt_more', 'new_excerpt_more');



     /**
     * Register sidebars for munix
     */

function munix_sidebars() {

	// Blog Sidebar

	register_sidebar(array(
		'name' => esc_html__( 'Blog Sidebar', "munix"),
		'id' => 'blog-sidebar',
		'description' => esc_html__( 'Sidebar on the blog layout.', "munix"),
		'before_widget' => '<div id="%1$s" class="widget %2$s">',
		'after_widget' => '</div>',
		'before_title' => '<div class="all-title"><h3 class="sec-title">',
		'after_title' => '</h3></div>',
	));
  	

	// Footer Sidebar

	register_sidebar(array(
		'name' => esc_html__( 'Footer Widget Area 1', "munix"),
		'id' => 'munix-footer-widget-area-1',
		'description' => esc_html__( 'The footer widget area 1', "munix"),
		'before_widget' => ' <div class="company-details %2$s">',
		'after_widget' => '</div> ',
		'before_title' => '<h3 class="foot-title">',
		'after_title' => '</h3>',
	));	
	

	register_sidebar(array(
		'name' => esc_html__( 'Footer Widget Area 2', "munix"),
		'id' => 'munix-footer-widget-area-2',
		'description' => esc_html__( 'The footer widget area 2', "munix"),
		'before_widget' => '<div class="useful-links %2$s"> ',
		'after_widget' => ' </div>',
		'before_title' => '<h3 class="foot-title">',
		'after_title' => '</h3>',
	));	
	
	register_sidebar(array(
		'name' => esc_html__( 'Footer Widget Area 3', "munix"),
		'id' => 'munix-footer-widget-area-3',
		'description' => esc_html__( 'The footer widget area 3', "munix"),
		'before_widget' => '<div class="recent-post %2$s">',
		'after_widget' => '</div>',
		'before_title' => '<h3 class="foot-title">',
		'after_title' => '</h3>',
	));	
	
	register_sidebar(array(
		'name' => esc_html__( 'Footer Widget Area 4', "munix"),
		'id' => 'munix-footer-widget-area-4',
		'description' => esc_html__( 'The footer widget area 4', "munix"),
		'before_widget' => '<div class="insta-feed %2$s">',
		'after_widget' => '</div>',
		'before_title' => '<h3 class="foot-title">',
		'after_title' => '</h3>',
	));		
}

add_action( 'widgets_init', 'munix_sidebars' );
/**
 * Comment layout
 */
function munix_comments( $comment, $args, $depth ) { ?>
	<div <?php comment_class('comments'); ?> id="<?php comment_ID() ?>">
		<?php if ($comment->comment_approved == '0') : ?>
			<div class="alert alert-info">
			  <p><?php esc_html_e( 'Your comment is awaiting moderation.', 'munix' ) ?></p>
			</div>
		<?php endif; ?>
		
		<div class="comment-wrap">
			<div class="comment-inner">
				
				<div class="com-img">
			    <?php echo get_avatar( $comment,'88', null,'User', array( 'class' => array( 'media-object','' ) )); ?>
			</div>
			<div class="comm-content">
			    <h5 class="rpl">
				   <?php 
						/* translators: '%1$s %2$s: edit term */
				    printf(esc_html__( '%1$s %2$s', 'munix' ), get_comment_author_link(), edit_comment_link(esc_html__( '(Edit)', 'munix' ),'  ','') )
				    ?>
				    <span><?php the_date();?></span>
				    <?php comment_reply_link (array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth']))) ?>
			     </h5>
			    
			    <?php comment_text() ;?>
			    </div>
		    </div>
		</div>
	</div>
<?php
} 
 
/**
 * Customizer additions.
 */
  require get_template_directory(). '/customizer.php';

   
/**
 * Functions hooked to core hooks.
 *
 */

if ( ! function_exists( 'munix_customize_search_form' ) ) :

	/** Customize search form.
	 **/
	function munix_customize_search_form() {

		$form = '<form role="search" method="get" class="side-form" action="' . esc_url( home_url( '/' ) ) . '">
			<label>
			<span class="screen-reader-text">' . esc_html( '', 'label', 'munix' ) . '</span>
			<input type="search" class="search-query form-control" placeholder="' . esc_attr_x( 'Search', 'placeholder', 'munix' ) . '" value="' . get_search_query() . '" name="s" title="' . esc_attr_x( 'Search for:', 'label', 'munix' ) . '" />
			</label><button type="submit"> <i class="fa fa-search"></i> </button></form>';

		return $form;
    }
	
	endif;
add_filter( 'get_search_form', 'munix_customize_search_form', 15 );
?>
