/**
 * Clean Yeti Basic Theme Settings Theme Customizer Implementation
 *
 * Implement the Theme Customizer for the 
 * Clean Yeti Basic Theme Settings.
 * 
 * @param 	object	$wp_customize	Object that holds the customizer data
 * 
 * @link	http://ottopress.com/2012/how-to-leverage-the-theme-customizer-in-your-own-themes/	Otto
 */
function cleanyetibasic_register_theme_customizer($wp_customize)
{
    // Failsafe is safe
    if (!isset($wp_customize)) {
        return;
    }
    global $cleanyetibasic_options;
    $cleanyetibasic_options = cleanyetibasic_get_options();
    // Get the array of option parameters
    $option_parameters = cleanyetibasic_get_option_parameters();
    // Get list of tabs
    $tabs = cleanyetibasic_get_settings_page_tabs();
    // Add Sections
    foreach ($tabs as $tab) {
        // Add $tab section
        $wp_customize->add_section('cleanyetibasic_' . $tab['name'], array('title' => $tab['title']));
    }
    // Add Settings
    foreach ($option_parameters as $option_parameter) {
        // sanitize callback based on type
        if ('text' == $option_parameter['type']) {
            $sanitize = 'cleanyetibasic_sanitize_text';
        } else {
            if ('checkbox' == $option_parameter['type']) {
                $sanitize = 'cleanyetibasic_sanitize_checkbox';
            } else {
                if ('radio' == $option_parameter['type'] || 'select' == $option_parameter['type']) {
                    $sanitize = 'cleanyetibasic_sanitize_choices';
                } else {
                    if ('color-picker' == $option_parameter['type']) {
                        $sanitize = 'sanitize_hex_color';
                    }
                }
            }
        }
        // Add $option_parameter setting
        $wp_customize->add_setting('theme_cleanyetibasic_options[' . $option_parameter['name'] . ']', array('default' => $option_parameter['default'], 'type' => 'option', 'sanitize_callback' => $sanitize));
        // Add $option_parameter control
        if ('text' == $option_parameter['type']) {
            $wp_customize->add_control('cleanyetibasic_' . $option_parameter['name'], array('label' => $option_parameter['title'], 'section' => 'cleanyetibasic_' . $option_parameter['tab'], 'settings' => 'theme_cleanyetibasic_options[' . $option_parameter['name'] . ']', 'type' => 'text'));
        } else {
            if ('checkbox' == $option_parameter['type']) {
                $wp_customize->add_control('cleanyetibasic_' . $option_parameter['name'], array('label' => $option_parameter['title'], 'section' => 'cleanyetibasic_' . $option_parameter['tab'], 'settings' => 'theme_cleanyetibasic_options[' . $option_parameter['name'] . ']', 'type' => 'checkbox'));
            } else {
                if ('radio' == $option_parameter['type']) {
                    $valid_options = array();
                    foreach ($option_parameter['valid_options'] as $valid_option) {
                        $valid_options[$valid_option['name']] = $valid_option['title'];
                    }
                    $wp_customize->add_control('cleanyetibasic_' . $option_parameter['name'], array('label' => $option_parameter['title'], 'section' => 'cleanyetibasic_' . $option_parameter['tab'], 'settings' => 'theme_cleanyetibasic_options[' . $option_parameter['name'] . ']', 'type' => 'radio', 'choices' => $valid_options));
                } else {
                    if ('select' == $option_parameter['type']) {
                        $valid_options = array();
                        foreach ($option_parameter['valid_options'] as $valid_option) {
                            $valid_options[$valid_option['name']] = $valid_option['title'];
                        }
                        $wp_customize->add_control('cleanyetibasic_' . $option_parameter['name'], array('label' => $option_parameter['title'], 'section' => 'cleanyetibasic_' . $option_parameter['tab'], 'settings' => 'theme_cleanyetibasic_options[' . $option_parameter['name'] . ']', 'type' => 'select', 'choices' => $valid_options));
                    } else {
                        if ('color-picker' == $option_parameter['type']) {
                            $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'cleanyetibasic_' . $option_parameter['name'], array('label' => $option_parameter['title'], 'section' => 'cleanyetibasic_' . $option_parameter['tab'], 'settings' => 'theme_cleanyetibasic_options[' . $option_parameter['name'] . ']')));
                        } else {
                            if ('custom' == $option_parameter['type']) {
                                $valid_options = array();
                                foreach ($option_parameter['valid_options'] as $valid_option) {
                                    $valid_options[$valid_option['name']] = $valid_option['title'];
                                }
                                $wp_customize->add_control('cleanyetibasic_' . $option_parameter['name'], array('label' => $option_parameter['title'], 'section' => 'cleanyetibasic_' . $option_parameter['tab'], 'settings' => 'theme_cleanyetibasic_options[' . $option_parameter['name'] . ']', 'type' => 'select', 'choices' => $valid_options));
                            }
                        }
                    }
                }
            }
        }
    }
}
 /**
  *
  * Child themes should use wp_dequeue_scripts to remove individual scripts.
  * Larger changes can be made using the override.
  *
  * Override: childtheme_override_head_scripts <br>
  *
  * @since 1.0
  */
 function cleanyetibasic_head_scripts()
 {
     global $cleanyetibasic_options;
     $cleanyetibasic_options = cleanyetibasic_get_options();
     $option_parameters = cleanyetibasic_get_option_parameters();
     if (is_singular() && comments_open() && get_option('thread_comments')) {
         has_filter('cleanyetibasic_show_commentreply') ? cleanyetibasic_show_commentreply() : wp_enqueue_script('comment-reply');
     }
     wp_enqueue_script('cleanyetibasic-modernizr-js', get_template_directory_uri() . '/library/Foundation/js/modernizr.js', array('jquery'), '2.8.3');
     wp_enqueue_script('cleanyetibasic-foundation-js', get_template_directory_uri() . '/library/Foundation/js/foundation/foundation.js', array(), '5.4.1', true);
     wp_enqueue_script('cleanyetibasic-foundation-accordion-js', get_template_directory_uri() . '/library/Foundation/js/foundation/foundation.accordion.js', array(), '5.4.1', true);
     wp_enqueue_script('cleanyetibasic-foundation-tabs-js', get_template_directory_uri() . '/library/Foundation/js/foundation/foundation.tab.js', array(), '5.4.1', true);
     wp_enqueue_script('cleanyetibasic-foundation-topbar-js', get_template_directory_uri() . '/library/Foundation/js/foundation/foundation.topbar.js', array(), '5.4.1', true);
     foreach ($option_parameters as $option_parameter) {
         $section = $option_parameter['section'];
         $name = $option_parameter['name'];
         if ('javascript' == $section && isset($cleanyetibasic_options[$name]) && 1 == $cleanyetibasic_options[$name]) {
             wp_enqueue_script('cleanyetibasic-foundation-' . $name . '-js', get_template_directory_uri() . '/library/Foundation/js/foundation/foundation.' . $name . '.js', array(), '5.4.1', true);
         }
     }
     wp_enqueue_script('cleanyetibasic-document-js', get_template_directory_uri() . '/library/Foundation/js/document.js', array(), '5.4.1', true);
 }
/**
 * Callback for get_settings_field()
 */
function cleanyetibasic_setting_callback($option)
{
    $cleanyetibasic_options = cleanyetibasic_get_options();
    $option_parameters = cleanyetibasic_get_option_parameters();
    $optionname = $option['name'];
    $optiontitle = $option['title'];
    $optiondescription = $option['description'];
    $fieldtype = $option['type'];
    $fieldname = 'theme_cleanyetibasic_options[' . $optionname . ']';
    // Output checkbox form field markup
    if ('checkbox' == $fieldtype) {
        ?>
		<input type="checkbox" name="<?php 
        echo $fieldname;
        ?>
" <?php 
        checked($cleanyetibasic_options[$optionname]);
        ?>
 />
		<?php 
    } else {
        if ('radio' == $fieldtype) {
            $valid_options = array();
            $valid_options = $option['valid_options'];
            foreach ($valid_options as $valid_option) {
                ?>
			<input type="radio" name="<?php 
                echo $fieldname;
                ?>
" <?php 
                checked($valid_option['name'] == $cleanyetibasic_options[$optionname]);
                ?>
 value="<?php 
                echo $valid_option['name'];
                ?>
" />
			<span>
			<?php 
                echo $valid_option['title'];
                ?>
			<?php 
                if ($valid_option['description']) {
                    ?>
				<span style="padding-left:5px;"><em><?php 
                    echo $valid_option['description'];
                    ?>
</em></span>
			<?php 
                }
                ?>
			</span>
			<br />
			<?php 
            }
        } else {
            if ('select' == $fieldtype) {
                $valid_options = array();
                $valid_options = $option['valid_options'];
                ?>
		<select name="<?php 
                echo $fieldname;
                ?>
">
		<?php 
                foreach ($valid_options as $valid_option) {
                    ?>
			<option <?php 
                    selected($valid_option['name'] == $cleanyetibasic_options[$optionname]);
                    ?>
 value="<?php 
                    echo $valid_option['name'];
                    ?>
"><?php 
                    echo $valid_option['title'];
                    ?>
</option>
			<?php 
                }
                ?>
		</select>
		<?php 
            } else {
                if ('text' == $fieldtype) {
                    ?>
		<input type="text" name="<?php 
                    echo $fieldname;
                    ?>
" value="<?php 
                    echo wp_filter_nohtml_kses($cleanyetibasic_options[$optionname]);
                    ?>
" />
		<?php 
                } else {
                    if ('color-picker' == $fieldtype) {
                        ?>
		<input type="text" class="cyb-color-field" name="<?php 
                        echo $fieldname;
                        ?>
" value="<?php 
                        echo wp_filter_nohtml_kses($cleanyetibasic_options[$optionname]);
                        ?>
" data-default-color="<?php 
                        echo $option['default'];
                        ?>
"/>
		<?php 
                    }
                }
            }
        }
    }
    // Output the setting description
    ?>
	<span class="description"><?php 
    echo $optiondescription;
    ?>
</span>
	<?php 
}
/**
 * Separate settings by tab
 * 
 * Returns an array of tabs, each of
 * which is an indexed array of settings
 * included with the specified tab.
 *
 * @uses	cleanyetibasic_get_option_parameters()	defined in \functions\options.php
 * @uses	cleanyetibasic_get_settings_page_tabs()	defined in \functions\options.php
 * 
 * @return	array	$settingsbytab	array of arrays of settings by tab
 */
function cleanyetibasic_get_settings_by_tab()
{
    // Get the list of settings page tabs
    $tabs = cleanyetibasic_get_settings_page_tabs();
    // Initialize an array to hold
    // an indexed array of tabnames
    $settingsbytab = array();
    // Loop through the array of tabs
    foreach ($tabs as $tab) {
        $tabname = $tab['name'];
        // Add an indexed array key
        // to the settings-by-tab
        // array for each tab name
        $settingsbytab[] = $tabname;
    }
    // Get the array of option parameters
    $option_parameters = cleanyetibasic_get_option_parameters();
    // Loop through the option parameters
    // array
    foreach ($option_parameters as $option_parameter) {
        $optiontab = $option_parameter['tab'];
        $optionname = $option_parameter['name'];
        // Add an indexed array key to the
        // settings-by-tab array for each
        // setting associated with each tab
        $settingsbytab[$optiontab][] = $optionname;
        $settingsbytab['all'][] = $optionname;
    }
    // Return the settings-by-tab
    // array
    return $settingsbytab;
}