<?php

//Add theme support for thumbnails and feed links
add_theme_support( 'post-thumbnails' ); 
add_theme_support( 'automatic-feed-links' ); 

//Add support for custom background
add_custom_background();

//Add Editor Style
add_theme_support('editor_style');
add_editor_style('tinymce-styles.css');


//Register Sidebar Widget Area
if ( function_exists( 'register_sidebar' ) )
register_sidebar(array( 'name' => 'sidebar',
'description' => __('Widgets you add here will be added to the sidebar', 'sidebar'),
'before_widget' => '',
'after_widget' => '',
'before_title' => '<h4>',
'after_title' => '</h4>',
));

// add menu support and fallback menu if menu doesn't exist
add_action( 'init', 'arnold_register_menu' );
function arnold_register_menu() {
	if (function_exists( 'register_nav_menu' )) {
		register_nav_menu( 'arnold-main-menu', __( 'Main Menu', 'tweaker' ));
	}
}
function arnold_default_menu() {
	echo '<ul class="menu">';
	if(is_home() && !is_paged()) {
		echo '<li class="current_page_item"><a href="'. home_url( '/' ) . '" title="You are Home" rel="nofollow">Home</a></li>';
	} else {
		echo '<li><a href="'. home_url( '/' ) . '" title="Click for Home" rel="nofollow">Home</a></li>';
	}
	wp_list_pages( 'title_li=' );
	wp_register();
	wp_meta();
	echo '</ul>';
}

//Set Comments
function mytheme_comment($comment, $args, $depth) {
   $GLOBALS[ 'comment' ] = $comment; ?>
   <li <?php comment_class(); ?> id="li-comment-<?php comment_ID() ?>">
     <div id="comment-<?php comment_ID(); ?>">
      <div class="comment-author vcard">
         <?php echo get_avatar($comment,$size='90' ); ?>
			<?php printf(__( '<cite class="fn">%s</cite> <span class="says">commented:</span>' ), get_comment_author_link()) ?>
	  </div>
      <?php if ($comment->comment_approved == '0') : ?>
         <em><?php _e( "Your comment is awaiting moderation.", "tweaker2" ) ?></em>
         <br />
      <?php endif; ?>

      <div class="comment-meta commentmetadata"><a href="<?php echo htmlspecialchars( get_comment_link( $comment->comment_ID ) ) ?>"><?php printf(__( '%1$s at %2$s' ), get_comment_date(),  get_comment_time()) ?></a><?php edit_comment_link(__( '(Edit)' ),'  ','') ?></div>

      <?php comment_text() ?>

      <div class="reply">
         <?php comment_reply_link(array_merge( $args, array( 'depth' => $depth, 'max_depth' => $args[ 'max_depth' ]))) ?>
      </div>
     </div>
<?php
}

//Set content width
$content_width = 640; 

//Linking date to date archives
add_shortcode( 'entry-link-published', 'my_entry_published_link' );
function my_entry_published_link() {
	/* Get the year, month, and day of the current post. */
	$year = get_the_time( 'Y' );
	$month = get_the_time( 'm' );
	$day = get_the_time( 'j' );
	$out = '';
	/* Add a link to the daily archive. */
	$out .= '<a href="' . get_day_link( $year, $month, $day ) . '" title="Archive for ' . esc_attr( get_the_time( 'j F Y' ) ) . '">' . $day . '</a>';
	/* Add a link to the monthly archive. */
	$out .= ' <a href="' . get_month_link( $year, $month ) . '" title="Archive for ' . esc_attr( get_the_time( 'F Y' ) ) . '">' . get_the_time( 'F' ) . '</a>';
	/* Add a link to the yearly archive. */
	$out .= ' <a href="' . get_year_link( $year ) . '" title="Archive for ' . esc_attr( $year ) . '">' . $year . '</a>';
	return $out;
}

//Custom Header
define('HEADER_TEXTCOLOR', 'fff');
define('HEADER_IMAGE', '%s/images/default.jpg');
define('HEADER_IMAGE_WIDTH', 980);
define('HEADER_IMAGE_HEIGHT', 120);

function header_style() {
?>
<style type="text/css">
#header{
    background: url(<?php header_image() ?>) no-repeat;
    height: <?php echo HEADER_IMAGE_HEIGHT; ?>px;
    width:<?php echo HEADER_IMAGE_WIDTH; ?>px;
    padding:0 0 0 18px;
    font-family: Arial;
}
#header h1 {
    padding:20px 0 0 0;
    margin: 0;
	line-height: 1;
}
#desc {
	padding: 0;
	margin: 0;
	line-height: 1;
}
<?php
if ( 'blank' == get_header_textcolor() ) { ?>
#header h1, #header #desc {
    display: none;
}
<?php } else {
    ?>
#header h1 a, #desc {
    color:#<?php header_textcolor() ?>;
}
<?php } ?>
</style>
<?php
}
function admin_header_style() {
?>
<style type="text/css">
#headimg{
    background: url(<?php header_image() ?>) no-repeat;
    height: <?php echo HEADER_IMAGE_HEIGHT; ?>px;
    width:<?php echo HEADER_IMAGE_WIDTH; ?>px;
    padding:0 0 0 18px;
    font-family: arial;
}
#headimg h1{
    padding-top:20px;
    margin: 0;
}
#headimg h1 a, #desc{
    color:#<?php header_textcolor() ?>;
    text-decoration: none;
    border-bottom: none;
}
#desc {
    padding-top: 15px;
}
<?php if ( 'blank' == get_header_textcolor() ) { ?>
#headimg h1, #headimg #desc {
    display: none;
}
#headimg h1 a, #headimg #desc {
    color:#<?php echo HEADER_TEXTCOLOR ?>;
}
<?php } ?>
</style>
<?php
}
add_custom_image_header('header_style', 'admin_header_style');
//Automate copyright dates
function arnold_copyright() {
global $wpdb;
$start_date = $wpdb->get_results("SELECT YEAR(min(post_date_gmt)) AS startdate FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'post'");
$output = '';
if($start_date) {
$copyright = "&copy; " . $start_date[0]->startdate . ' ';
if($start_date[0]->startdate != date( "Y" )) {
$copyright .= '- ' . date( "Y" ) . ' ';
}
$output = $copyright;
}
return $output;
}
?>