<?php

//////////////////////////////////////////////////////////////////
// Set Content Width
//////////////////////////////////////////////////////////////////

if ( ! isset( $content_width ) ) {
		$content_width = 1170;
	}



//////////////////////////////////////////////////////////////////
// Theme set up
//////////////////////////////////////////////////////////////////

if ( ! function_exists( 'bug_blog_theme_setup' ) ) :

function bug_blog_theme_setup(){

	// Localization support
	load_theme_textdomain( 'bug-blog', get_template_directory() . '/languages' );

	// Add default posts and comments RSS feed links to head.
	add_theme_support( 'automatic-feed-links' );

	// Title Tag
	add_theme_support( 'title-tag' );

	// Register navigation menu
	register_nav_menus( 
		array(
			'main-menu' 		=> __( 'Primary Menu','bug-blog' )
		) );


	// Switch default core markup for search form, comment form, and comments to output valid HTML5.
	add_theme_support( 'html5', array(
		'comment-form', 'comment-list', 'gallery', 'caption',
	) );

	// Set up the WordPress core custom background feature.
	add_theme_support( 'custom-background', apply_filters( 'bug_blog_custom_background_args', array(
		'default-color' => 'ffffff',
		'default-image' => '',
	) ) );

	// Post Formats
	add_theme_support( 'post-formats', array( 'gallery', 'video', 'audio' ) );

	$args = '';

	//add_theme_support( "custom-header", $args );
	// Post thumbnails
	add_theme_support( 'post-thumbnails' );
	add_image_size( 'post-thumbnails', 1140, 600, TRUE );
	add_image_size( 'related-image', 590, 390, TRUE );
	add_image_size('bug-blog-thumb', 60, 60, TRUE);

}
endif; // bug_blog_theme_setup

add_action( 'after_setup_theme', 'bug_blog_theme_setup' );

function bug_blog_add_editor_styles() {
	add_editor_style( 'custom-editor-style.css' );
}
add_action( 'admin_init', 'bug_blog_add_editor_styles' );

//////////////////////////////////////////////////////////////////
// Register widget
//////////////////////////////////////////////////////////////////

if ( function_exists('register_sidebar') ) {
	register_sidebar( array(
		'name'          => __( 'Sidebar', 'bug-blog' ),
		'id'            => 'blog-sidebar',
		'description'   => '',
		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
		'after_widget'  => '</aside>',
		'before_title'  => '<h1 class="widget-title">',
		'after_title'   => '</h1>',
	) );
	register_sidebar( array(
		'name'          => __( 'Footer', 'bug-blog' ),
		'id'            => 'footer-widget',
		'description'   => '',
		'before_widget' => '<aside id="%1$s" class="widget col-md-4 footer-widget %2$s">',
		'after_widget'  => '</aside>',
		'before_title'  => '<h1 class="widget-title">',
		'after_title'   => '</h1>',
	) );
}



//////////////////////////////////////////////////////////////////
// Enqueue scripts and styles.
//////////////////////////////////////////////////////////////////

function bug_blog_all_scripts_and_css() {
	
	// CSS File
	wp_enqueue_style('bootstrap-css', get_template_directory_uri() . '/assets/css/bootstrap.min.css', array(), '3.3.6', 'all');
	wp_enqueue_style('font-awesome', get_template_directory_uri() . '/assets/css/font-awesome.min.css', array(), '4.4.0', 'all');
	wp_enqueue_style('slicknav-css', get_template_directory_uri() . '/assets/css/slicknav.css', array(), NULL);
	wp_enqueue_style( 'bug_blog-stylesheet', get_stylesheet_uri() );
	wp_enqueue_style('bug_blog-responsive', get_template_directory_uri() . '/assets/css/responsive.css', array(), NULL);

	// Google Fonts
	wp_enqueue_style( 'google-font-open-sans', 'https://fonts.googleapis.com/css?family=Muli:200,200i,300,300i,400,400i,600,600i,700,700i,800,800i,900,900i', array(), NULL );
	wp_enqueue_style( 'Material+Icons', 'https://fonts.googleapis.com/icon?family=Material+Icons', array(), NULL );
	wp_enqueue_style( 'Muli', 'https://fonts.googleapis.com/css?family=Muli:400,700,800,900', array(), NULL );

	// JS Files
	wp_enqueue_script( 'jquery-bootstrap', get_template_directory_uri() . '/assets/js/bootstrap.min.js', array('jquery'), '3.3.6', TRUE );
	wp_enqueue_script( 'jquery-smoothscroll', get_template_directory_uri() . '/assets/js/smoothscroll.js', array('jquery'), '0.9.9', TRUE );
	wp_enqueue_script( 'jquery-slicknav', get_template_directory_uri() . '/assets/js/jquery.slicknav.js', array('jquery'), NULL, TRUE );
	wp_enqueue_script( 'jquery-fitvids', get_template_directory_uri() . '/assets/js/jquery.fitvids.js', array('jquery'), '1.1', TRUE );
	wp_enqueue_script( 'bug_blog-scripts', get_template_directory_uri() . '/assets/js/scripts.js', array('jquery'), NULL, TRUE );

	if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
		wp_enqueue_script( 'comment-reply' );
	}
}
add_action( 'wp_enqueue_scripts', 'bug_blog_all_scripts_and_css' );



function bug_blog_admin_enqueue_scripts() {


	wp_enqueue_script('jquery-ui-sortable');
	wp_enqueue_style( 'wp-color-picker' );

	wp_enqueue_script( 'bug_blog_scripts', get_template_directory_uri() . '/assets/admin/js/scripts.js', array( 'wp-color-picker' ), false, true );

	// CSS File
	wp_enqueue_style('bug-blog-admin-css', get_template_directory_uri() . '/assets/admin/css/style.css', array(), '4.4.0', 'all');
	wp_enqueue_style('font-awesome-css', get_template_directory_uri() . '/assets/css/font-awesome.min.css', array(), '4.4.0', 'all');


	// JS Files
	//wp_enqueue_script( 'scripts', get_template_directory_uri() . '/assets/admin/js/scripts.js', array('jquery'), '3.3.6', TRUE );

}

add_action( 'admin_enqueue_scripts', 'bug_blog_admin_enqueue_scripts' );










//////////////////////////////////////////////////////////////////
// COMMENTS LAYOUT
//////////////////////////////////////////////////////////////////

if(!function_exists('bug_blog_comment')):

	function bug_blog_comment($comment, $args, $depth)
	{
		//$GLOBALS['comment'] = $comment;
		switch ( $comment->comment_type ) :
			case 'pingback' :
			case 'trackback' :
			// Display trackbacks differently than normal comments.
		?>
		<li <?php comment_class(); ?> id="comment-<?php comment_ID(); ?>">
			<p><?php _e('Pingback:', 'bug-blog'); ?> <?php comment_author_link(); ?> <?php edit_comment_link( __( '(Edit)', 'bug-blog' ), '<span class="edit-link">', '</span>' ); ?></p>
		<?php
				break;
			default :
			
			global $post;
		?>
		<li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
			<div id="comment-<?php comment_ID(); ?>" class="comment-body media">
				
					<div class="comment-avartar">
						<?php
							echo get_avatar( $comment, $args['avatar_size'] );
						?>
					</div>
					<div class="comment-context media-body">
						<div class="comment-head">
							<?php
								printf( '<h3 class="comment-author">%1$s</h3>',
									get_comment_author_link());
							?>
							<span class="comment-date"><?php echo get_comment_date() ?></span>
						</div>

						<?php if ( '0' == $comment->comment_approved ) : ?>
						<p class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.',
								'bug-blog' ); ?></p>
						<?php endif; ?>

						<div class="comment-content">
							<?php comment_text(); ?>
						</div>

						<?php edit_comment_link( __( 'Edit', 'bug-blog' ), '<span class="edit-link comment-meta">', '</span>' ); ?>

						<span class="comment-reply comment-meta">
							<?php comment_reply_link( array_merge( $args, array( 'reply_text' => __( 'Reply', 'bug-blog'
							), 'after' => '', 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
						</span>

					</div>
				
			</div>
		<?php
			break;
		endswitch; 
	}

endif;







//////////////////////////////////////////////////////////////////
// Include files
//////////////////////////////////////////////////////////////////

// Theme Customizer
include('functions/customizer/customizer_settings.php');
include('functions/customizer/color_customize.php');
require get_template_directory() . '/inc/custom-header.php';

//Custom Widgets 
require_once get_template_directory()  . '/inc/widgets/blog-posts.php';
require_once get_template_directory()  . '/inc/widgets/social-icons.php';


// Custom template tags for this theme.
require_once get_template_directory() . '/inc/template-tags.php';



