<?php
 
/**
 * Setup the WordPress core custom header feature.
 *
 * Use add_theme_support to register support for WordPress 3.4+
 * as well as provide backward compatibility for previous versions.
 * Use feature detection of wp_get_theme() which was introduced
 * in WordPress 3.4.
 *
 * @uses safethree_header_style()
 * @uses safethree_admin_header_style()
 * @uses safethree_admin_header_image()
 *
 * @package safethree
 */
function safethree_custom_header_setup() {
    $args = array(
        'default-image'          => '',
        'default-text-color'     => 'e9e0e1',
        'width'                  => 348,
        'height'                 => 100,
        'flex-height'            => true,
        'wp-head-callback'       => 'safethree_header_style',
        'admin-head-callback'    => 'safethree_admin_header_style',
        'admin-preview-callback' => 'safethree_admin_header_image',
    );
 
    $args = apply_filters( 'safethree_custom_header_args', $args );
 
    if ( function_exists( 'wp_get_theme' ) ) {
        add_theme_support( 'custom-header', $args );
    } else {
        // Compat: Versions of WordPress prior to 3.4.
        define( 'HEADER_TEXTCOLOR',    $args['default-text-color'] );
        define( 'HEADER_IMAGE',        $args['default-image'] );
        define( 'HEADER_IMAGE_WIDTH',  $args['width'] );
        define( 'HEADER_IMAGE_HEIGHT', $args['height'] );
        add_custom_image_header( $args['wp-head-callback'], $args['admin-head-callback'], $args['admin-preview-callback'] );
    }
}
add_action( 'after_setup_theme', 'safethree_custom_header_setup' );
 
/**
 * Shiv for get_custom_header().
 *
 * get_custom_header() was introduced to WordPress
 * in version 3.4. To provide backward compatibility
 * with previous versions, we will define our own version
 * of this function.
 *
 * @todo Remove this function when WordPress 3.6 is released.
 * @return stdClass All properties represent attributes of the curent header image.
 *
 * @package safethree
 * @since safethree 1.1
 */
 

if ( ! function_exists( 'get_custom_header' ) ) {
    function get_custom_header() {
        return (object) array(
            'url'           => get_header_image(),
            'thumbnail_url' => get_header_image(),
            'width'         => HEADER_IMAGE_WIDTH,
            'height'        => HEADER_IMAGE_HEIGHT,
        );
    }
}
 
if ( ! function_exists( 'safethree_header_style' ) ) :
/**
 * Styles the header image and text displayed on the blog
 *
 * @see safethree_custom_header_setup().
 *
 * @since safethree 1.0
 */
function safethree_header_style() {
 
    // If no custom options for text are set, let's bail
    // get_header_textcolor() options: HEADER_TEXTCOLOR is default, hide text (returns 'blank') or any hex value
    if ( HEADER_TEXTCOLOR == get_header_textcolor() && '' == get_header_image() )
        return;
    // If we get this far, we have custom styles. Let's do this.
    ?>
    <style type="text/css">
    <?php
        // Do we have a custom header image?
        if ( '' != get_header_image() ) :
    ?>
        .site-header img {
            display: block;
            margin: 1.5em auto 0;
        }
    <?php endif;
 
        // Has the text been hidden?
        if ( 'blank' == get_header_textcolor() ) :
    ?>
        .site-title,
        .site-description {
            position: absolute !important;
            clip: rect(1px 1px 1px 1px); /* IE6, IE7 */
            clip: rect(1px, 1px, 1px, 1px);
        }
        .site-header hgroup {
            background: none;
            padding: 0;
        }
    <?php
        // If the user has set a custom color for the text use that
        else :
    ?>
        .site-title a,
        .site-description {
            color: #<?php echo get_header_textcolor(); ?> !important;
        }
    <?php endif; ?>
    </style>
    <?php
}
endif; // safethree_header_style
 
if ( ! function_exists( 'safethree_admin_header_style' ) ) :
/**
 * Styles the header image displayed on the Appearance > Header admin panel.
 *
 * @see safethree_custom_header_setup().
 *
 * @since safethree 1.0
 */
function safethree_admin_header_style() {
?>
    <style type="text/css">
  
    #desc { padding: 0 2em 2em; color: #e9e0d1; text-decoration: none;}
	/* @group Sidebar */
	#brand {background: #f9f9f9; border-radius:5px; width:348px; height:100px;}
	#brand-logo {float: left; width: 82px;  padding:10px;}
	#brand-logo img { -moz-border-radius: 10px; }
	#brand-info { font-size: 10px; width: 147px; float: left; margin-left:10px;}
	#brand-info p {line-height: 16px; margin: 0; padding:10px;}
	#brand-info h1 {font-size: 16px; margin: 0 0 5px; text-shadow: #fff 0 1px 0; line-height: 18px;}
	/* @brand */
    </style>
<?php
}
endif; // safethree_admin_header_style
 
if ( ! function_exists( 'safethree_admin_header_image' ) ) :
/**
 * Custom header image markup displayed on the Appearance > Header admin panel.
 *
 * @see safethree_custom_header_setup().
 *
 * @since safethree 1.0
 */
function safethree_admin_header_image() { ?>
    <div>
        <?php
        if ( 'blank' == get_header_textcolor() || '' == get_header_textcolor() ) $style = ' style="display:none;"';
        else $style = ' style="color:#' . get_header_textcolor() . ';"';
        
        
        $header_image=get_header_image();
        if ( ! empty( $header_image ) ){
        	$header_image="style=\"background:url('".$header_image."')\"";
        }else{
        	$header_image="";
        }
        ?>
        
        
        
	     <div id="brand" class="clearfix" <?php echo $header_image;?>>
			<div id="brand-logo" >
				<a href="<?php echo home_url(); ?>/">
					<?php if(get_option('sft_blog_image_enable') == 'on') : ?>
						<img src="<?php echo get_option('sft_blogImage'); ?>" alt="logo" width="80" />
					<?php else: ?>
						<?php $blog_email = get_bloginfo('admin_email');?>
						<img src="http://gravatar.com/avatar/<?php echo md5($blog_email); ?>?s=80" alt="Avatar" width="80" />
					<?php endif; ?>
				</a>
			</div>
			<div id="brand-info" <?php echo $style;?>><h1><a href="<?php echo home_url(); ?>/"><?php bloginfo('name'); ?></a></h1><p><?php bloginfo('description'); ?></p></div>
		</div>
	
        
        
      
    </div>
<?php }
endif; // safethree_admin_header_image