<?php
/**
 * Theia Theme Customizer
 *
 * @package Theia Lite
 */

/**
 * Add postMessage support for site title and description for the Theme Customizer.
 *
 * @param WP_Customize_Manager $wp_customize Theme Customizer object.
 */
function theia_lite_customize_register( $wp_customize ) {
	$wp_customize->get_setting( 'blogname' )->transport         = 'postMessage';
	$wp_customize->get_setting( 'blogdescription' )->transport  = 'postMessage';
}
add_action( 'customize_register', 'theia_lite_customize_register' );

/**
 * Binds JS handlers to make Theme Customizer preview reload changes asynchronously.
 */
function theia_lite_customize_preview_js() {
	wp_enqueue_script( 'theia_lite_customizer', get_template_directory_uri() . '/js/customizer.js', array( 'customize-preview' ), '20151215', true );
}
add_action( 'customize_preview_init', 'theia_lite_customize_preview_js' );

/**
 * Register Custom Settings
 */
function theia_lite_custom_settings_register( $wp_customize ) {
	
	/*
	Start Theia Lite Colors
	=====================================================
	*/
	
	$colors = array();
	
	$colors[] = array(
	'slug'=>'theia_lite_site_color_text', 
	'default' => '#6b6b6b',
	'label' => __('Text Color', 'theia-lite')
	);
	
	$colors[] = array(
	'slug'=>'theia_lite_site_color_sectext', 
	'default' => '#757575',
	'label' => __('Secondary Text Color', 'theia-lite')
	);
	
	$colors[] = array(
	'slug'=>'theia_lite_site_color_special', 
	'default' => '#008a19',
	'label' => __('Special Color', 'theia-lite')
	);
	
	$colors[] = array(
	'slug'=>'theia_lite_site_color_sidebar', 
	'default' => '#ffffff',
	'label' => __('Background Sidebar Color', 'theia-lite')
	);
	
	foreach( $colors as $theia_lite_theme_options ) {
		// SETTINGS
		$wp_customize->add_setting( 'theia_lite_theme_options[' . $theia_lite_theme_options['slug'] . ']', array(
			'default' => $theia_lite_theme_options['default'],
			'type' => 'option', 
			'sanitize_callback' => 'sanitize_hex_color',
			'capability' => 'edit_theme_options'
		)
		);
		// CONTROLS
		$wp_customize->add_control(
			new WP_Customize_Color_Control(
				$wp_customize,
				$theia_lite_theme_options['slug'], 
				array('label' => $theia_lite_theme_options['label'], 
				'section' => 'colors',
				'settings' =>'theia_lite_theme_options[' . $theia_lite_theme_options['slug'] . ']',
				)
			)
		);
	}
	
	/*
	Start Theia Lite Options
	=====================================================
	*/
	$wp_customize->add_section( 'geco_theia_lite_options', array(
	     'title'    => esc_attr__( 'Theia Lite Options', 'theia-lite' ),
	     'priority' => 50,
	) );
	
	/*
	Enable Sticky Menu
	=====================================================
	*/
	$wp_customize->add_setting('theia_lite_theme_options_stickymenu', array(
        'default'    => '',
        'type'       => 'theme_mod',
        'capability' => 'edit_theme_options',
		'sanitize_callback' => 'theia_lite_sanitize_checkbox'
    ) );
	
	$wp_customize->add_control('theia_lite_theme_options_stickymenu', array(
        'label'      => __( 'Enable Sticky Menu', 'theia-lite' ),
        'section'    => 'geco_theia_lite_options',
        'settings'   => 'theia_lite_theme_options_stickymenu',
        'type'       => 'checkbox',
		'priority' => 1,
    ) );
	
	/*
	Enable Menu Always Visible
	=====================================================
	*/
	$wp_customize->add_setting('theia_lite_theme_options_fixedmenu', array(
        'default'    => '',
        'type'       => 'theme_mod',
        'capability' => 'edit_theme_options',
		'sanitize_callback' => 'theia_lite_sanitize_checkbox'
    ) );
	
	$wp_customize->add_control('theia_lite_theme_options_fixedmenu', array(
        'label'      => __( 'Enable Menu Always Visible (Desktop)', 'theia-lite' ),
        'section'    => 'geco_theia_lite_options',
        'settings'   => 'theia_lite_theme_options_fixedmenu',
        'type'       => 'checkbox',
		'priority' => 2,
    ) );
	/*
	Sidebar Menu
	=====================================================
	*/
	$wp_customize->add_setting('theia_lite_theme_options_sidebarmenu', array(
        'default'    => '',
        'type'       => 'theme_mod',
        'capability' => 'edit_theme_options',
		'sanitize_callback' => 'theia_lite_sanitize_select'
    ) );
	
	$wp_customize->add_control('theia_lite_theme_options_sidebarmenu', array(
        'label'      => __( 'Sidebar Menu', 'theia-lite' ),
        'section'    => 'geco_theia_lite_options',
        'settings'   => 'theia_lite_theme_options_sidebarmenu',
        'type'       => 'radio',
		'priority' => 3,
        'choices'    => array(
            'value1' => 'Desktop + Mobile',
            'value2' => 'Only Mobile',
			)
    ) );
	/*
	Enable Logo - Site Title
	=====================================================
	*/
	$wp_customize->add_setting('theia_pro_theme_options_sidebarLogotheia', array(
        'default'    => '',
        'type'       => 'theme_mod',
        'capability' => 'edit_theme_options',
		'sanitize_callback' => 'theia_lite_sanitize_checkbox'
    ) );
	
	$wp_customize->add_control('theia_pro_theme_options_sidebarLogotheia', array(
        'label'      => __( 'Enable Logo/Site Title in sidebar', 'theia-lite' ),
        'section'    => 'geco_theia_lite_options',
        'settings'   => 'theia_pro_theme_options_sidebarLogotheia',
        'type'       => 'checkbox',
		'priority' => 4,
    ) );
	/*
	Start Theia Lite Social
	=====================================================
	*/
	$wp_customize->add_section( 'geco_theia_lite_socialmedia', array(
	     'title'    => esc_attr__( 'Theia Social Network', 'theia-lite' ),
	     'priority' => 50,
	) );
	
	/*
	Social Icons
	=====================================================
	*/
	$socialmedia = array();
	
	$socialmedia[] = array(
	'slug'=>'facebookurl', 
	'default' => '',
	'label' => __('Facebook URL', 'theia-lite')
	);
	$socialmedia[] = array(
	'slug'=>'twitterurl', 
	'default' => '',
	'label' => __('Twitter URL', 'theia-lite')
	);
	$socialmedia[] = array(
	'slug'=>'linkedinurl', 
	'default' => '',
	'label' => __('Linkedin URL', 'theia-lite')
	);
	$socialmedia[] = array(
	'slug'=>'instagramurl', 
	'default' => '',
	'label' => __('Instagram URL', 'theia-lite')
	);
	$socialmedia[] = array(
	'slug'=>'youtubeurl', 
	'default' => '',
	'label' => __('YouTube URL', 'theia-lite')
	);
	$socialmedia[] = array(
	'slug'=>'pinteresturl', 
	'default' => '',
	'label' => __('Pinterest URL', 'theia-lite')
	);
	$socialmedia[] = array(
	'slug'=>'tumblrurl', 
	'default' => '',
	'label' => __('Tumblr URL', 'theia-lite')
	);
	$socialmedia[] = array(
	'slug'=>'flickrurl', 
	'default' => '',
	'label' => __('Flickr URL', 'theia-lite')
	);
	$socialmedia[] = array(
	'slug'=>'vkurl', 
	'default' => '',
	'label' => __('VK URL', 'theia-lite')
	);
	$socialmedia[] = array(
	'slug'=>'facebookmessengerurl', 
	'default' => '',
	'label' => __('Facebook Messenger URL', 'theia-lite')
	);
	$socialmedia[] = array(
	'slug'=>'skypename', 
	'default' => '',
	'label' => __('Skype Name', 'theia-lite')
	);
	
	foreach( $socialmedia as $theia_lite_theme_options ) {
		// SETTINGS
		$wp_customize->add_setting(
			'theia_lite_theme_options_' . $theia_lite_theme_options['slug'], array(
				'default' => $theia_lite_theme_options['default'],
				'capability'     => 'edit_theme_options',
				'sanitize_callback' => 'esc_url_raw',
				'type'     => 'theme_mod',
			)
		);
		// CONTROLS
		$wp_customize->add_control(
			$theia_lite_theme_options['slug'], 
			array('label' => $theia_lite_theme_options['label'], 
			'section'    => 'geco_theia_lite_socialmedia',
			'settings' =>'theia_lite_theme_options_' . $theia_lite_theme_options['slug'],
			)
		);
	}
		
}

add_action( 'customize_register', 'theia_lite_custom_settings_register' );

function theia_lite_sanitize_checkbox( $input ) {
	if ( $input == 1 ) {
		return 1;
	} else {
		return '';
	}
}

function theia_lite_sanitize_select( $input ) {
	return wp_filter_nohtml_kses( $input );
}


/**
 * Add Custom CSS to Header 
 */
function theia_lite_custom_css_styles() { 
	global $theia_lite_theme_options;
	$se_options = get_option( 'theia_lite_theme_options', $theia_lite_theme_options );
	if( isset( $se_options[ 'theia_lite_site_color_text' ] ) ) {
		$theia_lite_site_color_text = $se_options['theia_lite_site_color_text'];
	}
	if( isset( $se_options[ 'theia_lite_site_color_sectext' ] ) ) {
		$theia_lite_site_color_sectext = $se_options['theia_lite_site_color_sectext'];
	}
	if( isset( $se_options[ 'theia_lite_site_color_special' ] ) ) {
		$theia_lite_site_color_special = $se_options['theia_lite_site_color_special'];
	}
	if( isset( $se_options[ 'theia_lite_site_color_sidebar' ] ) ) {
		$theia_lite_site_color_sidebar = $se_options['theia_lite_site_color_sidebar'];
	}
?>
<style type="text/css">
	<?php if (!empty($theia_lite_site_color_text) && $theia_lite_site_color_text != '#6b6b6b' ) : ?>
		body,
		button,
		input,
		select,
		textarea,
		a:hover,
		a:focus,
		a:active,
		body.single .content-theia .entry-meta a,
		aside.widget-area a,
		aside.widget-area a:focus,
		aside.widget-area a:active,
		aside.widget-area a:visited,
		.socialHeader i:hover,
		.socialFooter i,
		.theTheia-box .entry-title a,
		.site-footer a {
			color: <?php echo esc_attr($theia_lite_site_color_text); ?>;
		}
	<?php endif; ?>	
	<?php if (!empty($theia_lite_site_color_sectext) && $theia_lite_site_color_sectext != '#c5c5c5' ) : ?>
		.smallPart {
			color: <?php echo esc_attr($theia_lite_site_color_sectext); ?>;
		}
	<?php endif; ?>
	<?php if (!empty($theia_lite_site_color_special) && $theia_lite_site_color_special != '#008a19' ) : ?>
		a,
		body.single .content-theia .entry-meta a:hover,
		aside.widget-area a:hover,
		.socialHeader i,
		.socialFooter i:hover,
		#wp-calendar tbody td a,
		button:hover,
		input[type="button"]:hover,
		input[type="reset"]:hover,
		input[type="submit"]:hover,
		button:focus,
		input[type="button"]:focus,
		input[type="reset"]:focus,
		input[type="submit"]:focus,
		button:active,
		input[type="button"]:active,
		input[type="reset"]:active,
		input[type="submit"]:active{
			color: <?php echo esc_attr($theia_lite_site_color_special); ?>;
		}
		#secondary .widget-title:after,
		#wp-calendar tbody tr #today,
		.theTheia-box,
		.site-footer,
		button,
		input[type="button"],
		input[type="reset"],
		input[type="submit"],
		button:hover,
		input[type="button"]:hover,
		input[type="reset"]:hover,
		input[type="submit"]:hover,
		button:focus,
		input[type="button"]:focus,
		input[type="reset"]:focus,
		input[type="submit"]:focus,
		button:active,
		input[type="button"]:active,
		input[type="reset"]:active,
		input[type="submit"]:active{
			border-color: <?php echo esc_attr($theia_lite_site_color_special); ?>;
		}
		button,
		input[type="button"],
		input[type="reset"],
		input[type="submit"]{
			background: <?php echo esc_attr($theia_lite_site_color_special); ?>;
		}
	<?php endif; ?>
	<?php if (!empty($theia_lite_site_color_sidebar) && $theia_lite_site_color_sidebar != '#ffffff' ) : ?>
		.navigationOpen,
		.widget-area{
			background: <?php echo esc_attr($theia_lite_site_color_sidebar); ?>;
		}
	<?php endif; ?>
</style>
<?php 
}
add_action('wp_head', 'theia_lite_custom_css_styles');
?>