<?php
/**
 * Checkbox sanitization callback.
 */
function dulcie_sanitize_checkbox( $checked ) {
	// Boolean check.
	return ( ( isset( $checked ) && true == $checked ) ? true : false );
}

/**
 * Select sanitization callback example.
 *
 * - Sanitization: select
 * - Control: select, radio
 */
function dulcie_sanitize_select( $input, $setting ) {
	
	// Ensure input is a slug.
	$input = sanitize_key( $input );
	
	// Get list of choices from the control associated with the setting.
	$choices = $setting->manager->get_control( $setting->id )->choices;
	
	// If the input is a valid key, return it; otherwise, return the default.
	return ( array_key_exists( $input, $choices ) ? $input : $setting->default );
}


/**
 * Social Sharing Hook
 * @since 1.0.0
 *
 * @param int $post_id
 * @return void
 *
 */
if (!function_exists('dulcie_social_sharing')) :
    function dulcie_social_sharing($post_id)
    {
        $dulcie_url = get_the_permalink($post_id);
        $dulcie_title = get_the_title($post_id);
        $dulcie_image = get_the_post_thumbnail_url($post_id);
        
        //sharing url
        $dulcie_twitter_sharing_url = esc_url('http://twitter.com/share?text=' . $dulcie_title . '&url=' . $dulcie_url);
        $dulcie_facebook_sharing_url = esc_url('https://www.facebook.com/sharer/sharer.php?u=' . $dulcie_url);
        $dulcie_pinterest_sharing_url = esc_url('http://pinterest.com/pin/create/button/?url=' . $dulcie_url . '&media=' . $dulcie_image . '&description=' . $dulcie_title);
        $dulcie_linkedin_sharing_url = esc_url('http://www.linkedin.com/shareArticle?mini=true&title=' . $dulcie_title . '&url=' . $dulcie_url);
        
        ?>
        <div class="post-share">
            <a target="_blank" href="<?php echo $dulcie_facebook_sharing_url; ?>"><i class="fa fa-facebook"></i></a>
            <a target="_blank" href="<?php echo $dulcie_twitter_sharing_url; ?>"><i
                        class="fa fa-twitter"></i></a>
            <a target="_blank" href="<?php echo $dulcie_pinterest_sharing_url; ?>"><i
                        class="fa fa-pinterest"></i></a>
            <a target="_blank" href="<?php echo $dulcie_linkedin_sharing_url; ?>"><i class="fa fa-linkedin"></i></a>
        </div>
        <?php
    }
endif;
add_action('dulcie_social_sharing', 'dulcie_social_sharing', 10);


/**
 * Dulcie Add Body Class
 *
 * @since Dulcie 1.0.0
 *
 * @param string $classes CSS body classes.
 */
function dulcie_custom_class( $classes ) {
    $classes[] = 'pt-sticky-sidebar';

    $sidebar = get_theme_mod( 'dulcie-sidebar-options' );
    if ( 'right-sidebar' === $sidebar ) {
        $classes[] = 'has-right-sidebar';
    }else {
        $classes[] = 'no-sidebar';
    }
    return $classes;
}
add_filter( 'body_class', 'dulcie_custom_class' );