<?php
/**
 * Portfolio Icon Theme Options
 *
 * @package Portfolio Icon
 */

/**
 * Add theme options
 *
 * @param WP_Customize_Manager $wp_customize Theme Customizer object.
 */


// Customizer - Add CSS

function portfolioicon_customizer_css() {
        
    ?>
    <style type="text/css">

        <?php if( get_theme_mod('portfolioicon_site_layout', 'full') == 'full') : ?>
        .site-inner {
            
            width: 100%;
        }

        <?php elseif( get_theme_mod('portfolioicon_site_layout') == 'boxed') : ?>
        .site-inner {
            
            width: 90%;
        }

        <?php endif; ?>

        .archive-posts-wrapper .nav-links a, .first-post .hentry, .hero-content-wrapper .section-content-wrap:before,
        .single-footer-meta-wrapper:before, .footer-widget-area:before, #scrollup, #infinite-post-wrap #infinite-handle span
        { background-color:<?php echo esc_attr(get_theme_mod( 'portfolio_icon_site_color' )); ?>; }

    </style>
    <?php
}
add_action( 'wp_head', 'portfolioicon_customizer_css' );


function portfolioicon_theme_settings( $wp_customize ) {
	$wp_customize->add_panel( 'portfolioicon_theme_settings', array(
        'title'    => esc_html__( 'Theme Settings', 'portfolio-icon' ),
        'priority' => 130,
    ) );

    // Breadcrumb Option
    $wp_customize->add_section( 'portfolioicon_breadcrumb_options', array(
        'description'   => esc_html__( 'Breadcrumbs are a great way of letting your visitors find out where they are on your site with just a glance. You can enable/disable them on homepage and entire site.', 'portfolio-icon' ),
        'panel'         => 'portfolioicon_theme_settings',
        'title'         => esc_html__( 'Breadcrumb', 'portfolio-icon' ),
    ) );

    $wp_customize->add_setting( 'portfolioicon_breadcrumb_option', array(
        'default'           => 1,
        'sanitize_callback' => 'portfolioicon_sanitize_checkbox'
    ) );

    $wp_customize->add_control( 'portfolioicon_breadcrumb_option', array(
        'label'    => esc_html__( 'Check to enable Breadcrumb', 'portfolio-icon' ),
        'section'  => 'portfolioicon_breadcrumb_options',
        'type'     => 'checkbox',
    ) );
    // Breadcrumb Option End

    $wp_customize->add_section( 'portfolioicon_header_media_options', array(
        'title' => esc_html__( 'First Section', 'portfolio-icon' ),
        'panel' => 'portfolioicon_theme_settings',
        'priority' => 119
    ) );

    $wp_customize->add_setting( 'portfolioicon_header_media_text', array(
        'default'           => esc_html__( 'This is Header Media Text. You can edit this from Customizer', 'portfolio-icon' ),
        'sanitize_callback' => 'wp_kses_post',
    ) );

    $wp_customize->add_control( 'portfolioicon_header_media_text', array(
        'label'   => esc_html__( 'Header Media Text', 'portfolio-icon' ),
        'section' => 'portfolioicon_header_media_options',
        'type'    => 'textarea',
    ) );

    $wp_customize->add_section( 'portfolioicon_menu_options', array(
        'title' => esc_html__( 'Menu Options', 'portfolio-icon' ),
        'panel' => 'portfolioicon_theme_settings'
    ) );

    /* Menu Type */
    $wp_customize->add_setting( 'portfolioicon_menu_type', array(
        'default'           => 'default',
        'sanitize_callback' => 'portfolioicon_sanitize_select',
    ) );

    $wp_customize->add_control( 'portfolioicon_menu_type', array(
        'label'    => esc_html__( 'Menu Type', 'portfolio-icon' ),
        'section'  => 'portfolioicon_menu_options',
        'type'     => 'radio',
        'choices'  => array(
            'default' => esc_html__( 'Default', 'portfolio-icon' ),
            'classic' => esc_html__( 'Classic', 'portfolio-icon' ),
        ),
    ) );

    // Colors

    $wp_customize->add_section( 'portfolio_icon_new_section_site_colors' , array(
        'title'      => esc_html__('Site Colors', 'portfolio-icon'),
        'panel'      => 'portfolioicon_theme_settings',
    ) );

    $wp_customize->add_setting(
        'portfolio_icon_site_color',
        array(
            'default'     => '#434343',
            'sanitize_callback' => 'sanitize_hex_color'
        )
    );

    $wp_customize->add_control(
        new WP_Customize_Color_Control(
            $wp_customize,
            'portfolio_icon_site_color',
            array(
                'label'      => esc_html__('Site Color', 'portfolio-icon'),
                'section'    => 'colors',
                'settings'   => 'portfolio_icon_site_color',
                'priority'   => 2
            )
        )
    );

    $wp_customize->add_section( 'portfolioicon_layout_options', array(
        'title' => esc_html__( 'Single Page Layout', 'portfolio-icon' ),
        'panel' => 'portfolioicon_theme_settings'
    ) );

    /* Default Layout */
    $wp_customize->add_setting( 'portfolioicon_default_layout', array(
        'default'           => 'no-sidebar',
        'sanitize_callback' => 'portfolioicon_sanitize_select',
    ) );

    $wp_customize->add_control( 'portfolioicon_default_layout', array(
        'description'       => esc_html__( 'Layout for Singular Post Types like Post, Page', 'portfolio-icon' ),
         'label'    => esc_html__( 'Singular Content Layout', 'portfolio-icon' ),
        'section'  => 'portfolioicon_layout_options',
        'type'     => 'radio',
        'choices'  => array(
            'left-sidebar'          => esc_html__( 'Left Sidebar ( Primary Sidebar, Content )', 'portfolio-icon' ),
            'no-sidebar'            => esc_html__( 'No Sidebar', 'portfolio-icon' ),
        ),
    ) );

    $wp_customize->add_section( 'portfolioicon_site_layout', array(
            'title' => esc_html__( 'Site Layout', 'portfolio-icon' ),
            'panel' => 'portfolioicon_theme_settings'
    ) );

    /* Site default Layout */
    $wp_customize->add_setting( 'portfolioicon_site_layout', array(
        'default'           => 'full',
        'sanitize_callback' => 'portfolioicon_sanitize_select',
    ) );

    $wp_customize->add_control( 'portfolioicon_site_layout', array(
        'description'       => esc_html__( 'Site Layout: Boxed/Full', 'portfolio-icon' ),
        'label'    => esc_html__( 'Site Layout', 'portfolio-icon' ),
        'section'  => 'portfolioicon_site_layout',
        'type'     => 'radio',
        'choices'  => array(
            'full' => esc_html__('Full Width','portfolio-icon'),
            'boxed' => esc_html__('Boxed','portfolio-icon'),
        ),
    ) );

    // Excerpt Options
    $wp_customize->add_section( 'portfolioicon_excerpt_options', array(
        'panel'     => 'portfolioicon_theme_settings',
        'title'     => esc_html__( 'Excerpt Options', 'portfolio-icon' ),
    ) );

    $wp_customize->add_setting( 'portfolioicon_excerpt_length', array(
        'default'           => '30',
        'sanitize_callback' => 'absint',
    ) );

    $wp_customize->add_control( 'portfolioicon_excerpt_length', array(
        'description' => esc_html__('Excerpt length. Default is 30 words', 'portfolio-icon'),
        'input_attrs' => array(
            'min'   => 10,
            'max'   => 200,
            'step'  => 5,
            'style' => 'width: 60px;'
            ),
        'label'    => esc_html__( 'Excerpt Length (words)', 'portfolio-icon' ),
        'section'  => 'portfolioicon_excerpt_options',
        'type'     => 'number',
        )
    );

    $wp_customize->add_setting( 'portfolioicon_excerpt_more_text', array(
        'default'           => esc_html__( 'Continue reading', 'portfolio-icon' ),
        'sanitize_callback' => 'sanitize_text_field',
    ) );

    $wp_customize->add_control( 'portfolioicon_excerpt_more_text', array(
        'label'    => esc_html__( 'Read More Text', 'portfolio-icon' ),
        'section'  => 'portfolioicon_excerpt_options',
        'type'     => 'text',
    ) );
    // Excerpt Options End

    //Homepage / Frontpage Options
    $wp_customize->add_section( 'portfolioicon_homepage_options', array(
        'description' => esc_html__( 'Only posts that belong to the categories selected here will be displayed on the front page', 'portfolio-icon' ),
        'panel'       => 'portfolioicon_theme_settings',
        'title'       => esc_html__( 'Homepage Options', 'portfolio-icon' ),
    ) );

    $wp_customize->add_setting( 'portfolioicon_front_page_category', array(
        'default'           => array(),
        'sanitize_callback' => 'portfolioicon_sanitize_category_list',
    ) );

    $wp_customize->add_control( new PortfolioIconCustomizeDropdownCategoriesControl( $wp_customize, 'portfolioicon_front_page_category', array(
        'label'             => esc_html__( 'Select Categories', 'portfolio-icon' ),
        'name'              => 'portfolioicon_front_page_category',
        'section'           => 'portfolioicon_homepage_options',
        'type'              => 'dropdown-categories',
    ) ) );

    // Disable Recent post in static frontpage
    $wp_customize->add_setting( 'portfolioicon_enable_static_page_posts', array(
        'sanitize_callback' => 'portfolioicon_sanitize_checkbox',
    ) );

    $wp_customize->add_control( 'portfolioicon_enable_static_page_posts', array(
        'label'           => esc_html__( 'Check to Enable Recent Posts on Static Frontpage', 'portfolio-icon' ),
        'section'         => 'portfolioicon_homepage_options',
        'type'            => 'checkbox',
    ) );
    //Homepage / Frontpage Settings End


    // Pagination Options
    $nav_desc = sprintf( esc_html__( 'Infinite Scroll Options requires %1$sJetPack Plugin%2$s with Infinite Scroll module Enabled.', 'portfolio-icon' ), '<a target="_blank" href="' . esc_url( 'https://wordpress.org/plugins/jetpack/' ) . '">', '</a>' );

    $wp_customize->add_section( 'portfolioicon_pagination_options', array(
        'description'   => $nav_desc,
        'panel'         => 'portfolioicon_theme_settings',
        'title'         => esc_html__( 'Pagination Options', 'portfolio-icon' ),
    ) );

    $wp_customize->add_setting( 'portfolioicon_pagination_type', array(
        'default'           => 'default',
        'sanitize_callback' => 'portfolioicon_sanitize_select',
    ) );

    $wp_customize->add_control( 'portfolioicon_pagination_type', array(
        'choices'  => portfolioicon_get_pagination_types(),
        'label'    => esc_html__( 'Pagination type', 'portfolio-icon' ),
        'section'  => 'portfolioicon_pagination_options',
        'type'     => 'select',
    ) );
    // Pagination Options End

    /* Scrollup Options */
    $wp_customize->add_section( 'portfolioicon_scrollup', array(
        'panel'    => 'portfolioicon_theme_settings',
        'title'    => esc_html__( 'Scrollup Options', 'portfolio-icon' ),
    ) );

    $wp_customize->add_setting( 'portfolioicon_disable_scrollup', array(
        'sanitize_callback' => 'portfolioicon_sanitize_checkbox',
    ) );

    $wp_customize->add_control( 'portfolioicon_disable_scrollup', array(
        'label'     => esc_html__( 'Check to disable Scroll Up', 'portfolio-icon' ),
        'section'   => 'portfolioicon_scrollup',
        'type'      => 'checkbox',
    ) );

     /* Footer Options */
    $wp_customize->add_section( 'portfolioicon_footer_option', array(
            'title' => esc_html__( 'Footer Settings', 'portfolio-icon' ),
            'panel' => 'portfolioicon_theme_settings'
    ) );

    /* Site default Layout */
    $wp_customize->add_setting( 'portfolioicon_footer_option', array(
        'default'           => esc_html__('Copyright © All right reserved', 'portfolio-icon'),
        'sanitize_callback' => 'sanitize_text_field',
    ) );

    $wp_customize->add_control('portfolioicon_footer_option',
    array(
        'label'    => esc_html__('Footer Copyright Text', 'portfolio-icon'),
        'section'  => 'portfolioicon_footer_option',
        'type'     => 'text',
    ));

    // google fonts
    require_once( dirname( __FILE__ ) . '/google-fonts/fonts.php' );

    $wp_customize->add_section( 'portfolio_icon_google_fonts', array(
        'title'    => esc_html__( 'Fonts', 'portfolio-icon' ),
        'priority' => 50,
        'panel'      => 'portfolioicon_theme_settings',
    ) );

    $wp_customize->add_setting( 'portfolio_icon_google_fonts_heading_font', array(
        'default'           => 'none',
        'type'              => 'theme_mod',
        'capability'        => 'edit_theme_options',
        'transport'         => 'postMessage',
        'sanitize_callback' => 'sanitize_text_field',
    ) );

    $wp_customize->add_control( 'portfolio_icon_google_fonts_heading_font', array(
        'label'    => esc_html__( 'Header Font', 'portfolio-icon' ),
        'section'  => 'portfolio_icon_google_fonts',
        'settings' => 'portfolio_icon_google_fonts_heading_font',
        'type'     => 'select',
        'choices'  => $font_choices,
    ) );

    $wp_customize->add_setting( 'portfolio_icon_google_fonts_body_font', array(
        'default'           => 'none',
        'type'              => 'theme_mod',
        'capability'        => 'edit_theme_options',
        'transport'         => 'postMessage',
        'sanitize_callback' => 'sanitize_text_field',
    ) );

    $wp_customize->add_control( 'portfolio_icon_google_fonts_body_font', array(
        'label'    => esc_html__( 'Body Font', 'portfolio-icon' ),
        'section'  => 'portfolio_icon_google_fonts',
        'settings' => 'portfolio_icon_google_fonts_body_font',
        'type'     => 'select',
        'choices'  => $font_choices,
    ) );
    // end google fonts
}
add_action( 'customize_register', 'portfolioicon_theme_settings' );



