<?php
/*********************/
require_once ( get_template_directory() . '/inc/dark-theme-options.php' );
require_once ( get_template_directory() . '/inc/dark-widgets.php' );
require_once ( get_template_directory() . '/inc/shortcode.php' );
/*********************/
add_filter( 'manage_edit-post_columns', 'dark_columns_filter', 10, 1 );
function dark_columns_filter( $columns ) {
    $column_thumbnail = array( 'thumbnail' => __( 'Featured image', 'mt-dark' ) );
    $columns = array_slice( $columns, 0, 1, true ) + $column_thumbnail + array_slice( $columns, 1, NULL, true );
    return $columns;
}
/*********************/
add_action( 'manage_posts_custom_column', 'dark_column_action', 10, 1 );
function dark_column_action( $column ) {
	global $post;
	switch ( $column ) {
		case 'thumbnail':
			echo get_the_post_thumbnail( $post->ID, 'edit-screen-thumbnail' );
			break;
	}
}
/*********************/
if ( ! isset( $content_width ) )
	$content_width = 580;
/*********************/
if ( ! function_exists('dark_change_mce_buttons') ) {
function dark_change_mce_buttons($initArray) {
	$initArray['theme_advanced_buttons3'] = 'sub,sup';
	$initArray['theme_advanced_buttons3_add_before'] = 'styleselect';
	$initArray['theme_advanced_styles'] = 'Float Left=alignleft,Float Right=alignright,List style: Tick=s_tick,List style: Arrow=s_arrow,Frame: Alert=s_alert,Frame: Warning=s_warning,Frame: Info=s_info,Frame: Border=s_border,Frame: Border dotted=s_border_dotted,Frame: Border top/bottom=s_border_top_bottom,Buttons=s_button,Buttons: alignleft=s_button_left,Buttons: alignright=s_button_right,Buttons: Full width=s_button_full,Width 1/3=s_width_1_3,Width 1/2=s_width_1_2,Width 2/3=s_width_2_3,Background color: Black=s_b_black,Background color: Grey=s_b_grey';
	return $initArray;
}
}
add_filter('tiny_mce_before_init', 'dark_change_mce_buttons');
/*********************/	
if ( ! function_exists('dark_tdav_css') ) {
	function dark_tdav_css($wp) {
		$wp .= ',' . get_stylesheet_directory_uri() . '/inc/css/tinymce.css';
		return $wp;
	}
}
add_filter( 'mce_css', 'dark_tdav_css' );
/*********************/	
/******dark_setup*******/
/*********************/
add_action( 'after_setup_theme', 'dark_setup' );

if ( ! function_exists( 'dark_setup' ) ):
	function dark_setup() {
load_theme_textdomain( 'mt-dark', get_template_directory() . '/languages' );
/*********************/	
add_editor_style();
/*********************/	
add_custom_background();
/*********************/	
function dark_widgets_init() {
	register_sidebar( array(
		'name' => __( 'Sidebar', 'mt-dark' ),
		'id' => 'sidebar380px',
		'description' => __( 'The primary widget area', 'mt-dark' ),
		'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
		'after_widget' => '</li>',
		'before_title' => '<h3 class="widget-title">',
		'after_title' => '</h3>',
	) );
	register_sidebar( array(
		'name' => __( 'First Footer Widget Area', 'mt-dark' ),
		'id' => 'first-footer-widget-area',
		'description' => __( 'The secondary footer widget area', 'mt-dark' ),
		'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
		'after_widget' => '</li>',
		'before_title' => '<h3 class="widget-title">',
		'after_title' => '</h3>',
	) );
	
	register_sidebar( array(
		'name' => __( 'Second Footer Widget Area', 'mt-dark' ),
		'id' => 'second-footer-widget-area',
		'description' => __( 'The second footer widget area', 'mt-dark' ),
		'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
		'after_widget' => '</li>',
		'before_title' => '<h3 class="widget-title">',
		'after_title' => '</h3>',
	) );
}
add_action( 'widgets_init', 'dark_widgets_init' );		
/*********************/	
function new_excerpt_length($length) {
	return 60;
}
add_filter('excerpt_length', 'new_excerpt_length');
/*********************/	
function dark_yetii_init() {
	wp_register_script('yetii', get_template_directory_uri() .'/js/yetii-min.js');
	wp_enqueue_script('yetii');
}
add_action('init', 'dark_yetii_init');
/*********************/	
 function dark_slide() {
    wp_enqueue_script('jquery');
	wp_register_script('dark-slide', get_template_directory_uri() .'/js/slides.min.jquery.js', array('jquery'));	   
}
add_action('init', 'dark_slide');
/*********************/	
 function dark_print() {
	wp_register_style('print', get_template_directory_uri() .'/print.css', '', '1.1','print');
	wp_enqueue_style('print');	   
}
add_action('wp_print_styles', 'dark_print');
/*********************/
if ( function_exists( 'add_theme_support' ) ){
add_theme_support( 'post-thumbnails' );
set_post_thumbnail_size( 100, 100, true );
set_post_thumbnail_size( 580, 200, true );
set_post_thumbnail_size( 580, 320, true );
add_image_size( 'edit-screen-thumbnail', 100, 100, true );
add_image_size('single_post', 580, 200, true);
add_image_size('slide', 580, 320, true);
add_theme_support( 'post-formats', array( 'aside', 'gallery','image','link' ) );
add_theme_support( 'automatic-feed-links' );
}
/*********************/	
if (function_exists('wp_nav_menu')) {
register_nav_menus(array('primary' => 'Primary Navigation'));
}
/*********************/
if ( ! function_exists('dark_link_format') ) {
function dark_link_format() {
    if ( ! preg_match( '/<a\s[^>]*?href=[\'"](.+?)[\'"]/is', get_the_content(), $matches ) )
		return false;
	return esc_url_raw( $matches[1] );
         
}
}
/*********************/	
function dark_recent_comments_style() {
	global $wp_widget_factory;
	remove_action( 'wp_head', array( $wp_widget_factory->widgets['WP_Widget_Recent_Comments'], 'recent_comments_style' ) );
}
add_action( 'widgets_init', 'dark_recent_comments_style' );
/*********************/	
function dark_menu_args( $args ) {
	$args['show_home'] = true;
	return $args;
}
add_filter( 'wp_page_menu_args', 'dark_menu_args' );
/*********************/	
add_filter('use_default_gallery_style', '__return_false');
/*********************/	
    define( 'HEADER_TEXTCOLOR', '' );
	define( 'HEADER_IMAGE', '%s/images/header.jpg' );
	define( 'HEADER_IMAGE_WIDTH', apply_filters( 'dark_header_image_width', 960 ) );
	define( 'HEADER_IMAGE_HEIGHT', apply_filters( 'dark_header_image_height', 176 ) );
	set_post_thumbnail_size( HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT, true );
	define( 'NO_HEADER_TEXT', true );
	add_custom_image_header( 'dark_header_style', 'dark_header_style' );
	register_default_headers( array(
		'head' => array(
			'url' => '%s/images/headers/head.jpg',
			'thumbnail_url' => '%s/images/headers/head-thumbnail.jpg',
			'description' => __( 'Head', 'mt-dark' )
		),
		'rock' => array(
			'url' => '%s/images/headers/rock.jpg',
			'thumbnail_url' => '%s/images/headers/rock-thumbnail.jpg',
			'description' => __( 'Rock', 'mt-dark' )
		)
	) );
/*********************/	
		if ( ! function_exists( 'dark_footer_classes' ) ) :
		function dark_footer_classes( $existing_classes ) {
		if ( is_active_sidebar( 'first-footer-widget-area' ) || is_active_sidebar( 'second-footer-widget-area' ))
		$classes[] = 'footer-widget';
		else
		$classes[] = 'footer-no-widget';
		return array_merge( $existing_classes, $classes );
		}
		add_filter( 'body_class', 'dark_footer_classes' );
		endif;
/*********************/	
function dark_header_style() {
?>
<style type="text/css">
#header {
	background:#150A04 url(<?php header_image();?>) no-repeat top right ;
	width: <?php echo HEADER_IMAGE_WIDTH;?>px;
    height: <?php echo HEADER_IMAGE_HEIGHT;?>px;
}
</style>
<?php
}
/*********************/
function dark_auto_excerpt_more( $more ) {
return '&hellip; <a href="'. get_permalink() . '">' . __('(more...)', 'mt-dark') . '</a>';
}
add_filter( 'excerpt_more', 'dark_auto_excerpt_more' );
/*********************/
if ( ! function_exists( 'dark_posted_on' ) ) :
function dark_posted_on() {
printf( __( '<a href="%1$s" title="%2$s" rel="bookmark">%3$s</a>' , 'mt-dark' ),
get_permalink(), esc_attr( get_the_time() ), get_the_date()	);
}
endif;
/*********************/
}
endif;// end dark_setup
/*********************/
if ( ! function_exists('dark_pagination') ) {
function dark_pagination() {
global $wp_query, $wp_rewrite;
$wp_query->query_vars['paged'] > 1 ? $current = $wp_query->query_vars['paged'] : $current = 1;

$pagination = array(
'base' => @add_query_arg('paged','%#%'),
'format' => '',
'total' => $wp_query->max_num_pages,
'current' => $current,
'show_all' => false,
'mid_size' => 4,
'end_size'     => 2,
'type' => 'plain'
);

if( $wp_rewrite->using_permalinks() )
$pagination['base'] = user_trailingslashit( trailingslashit( remove_query_arg( 's', get_pagenum_link( 1 ) ) ) . 'page/%#%/', 'paged' );

if( !empty($wp_query->query_vars['s']) )
$pagination['add_args'] = array( 's' => get_query_var( 's' ) );

echo '<div class="wp-pagenavi">' .paginate_links($pagination).'</div>' ;
}
}
/*********************/
if ( ! function_exists( 'custom_comments' ) ) :
function custom_comments( $comment, $args, $depth ) {
$GLOBALS['comment'] = $comment;
switch ( $comment->comment_type ) :
case '' :
	?>
	<li <?php comment_class();?> id="li-comment-<?php comment_ID();?>">
		<div id="comment-<?php comment_ID();?>">
		<div class="comment-author vcard">
			<?php echo get_avatar($comment, 40);?>
			<?php printf(__('%s <span class="says">says:</span>', 'mt-dark'), sprintf('<cite class="fn">%s</cite>', get_comment_author_link()));?>
		</div><!-- .comment-author .vcard -->
		<?php if ( $comment->comment_approved == '0' ) : ?>
			<em><?php _e('Your comment is awaiting moderation.', 'mt-dark');?></em>
			<br />
		<?php endif;?>

		<div class="comment-meta commentmetadata"><a href="<?php echo esc_url(get_comment_link($comment -> comment_ID));?>">
			<?php
			/* translators: 1: date, 2: time */
			printf(__('%1$s at %2$s', 'mt-dark'), get_comment_date(), get_comment_time());
 ?></a><?php edit_comment_link(__('(Edit)', 'mt-dark'), ' ');?>
		</div><!-- .comment-meta .commentmetadata -->

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

		<div class="reply">
			<?php comment_reply_link(array_merge($args, array('depth' => $depth, 'max_depth' => $args['max_depth'])));?>
		</div><!-- .reply -->
	</div><!-- #comment-##  -->

	<?php
	break;
	case 'pingback'  :
	case 'trackback' :
	?>
	<li class="post pingback">
		<p><?php _e('Pingback:', 'mt-dark');?> <?php comment_author_link();?><?php edit_comment_link(__('(Edit)', ''), 'mt-dark');?></p>
	<?php
	break;
	endswitch;
	}
	endif;
?>
