<?php
/**
 * @package Delicacy
 */

// Content width
if ( ! isset( $content_width ) )
	$content_width = 600;

// Theme Setup

function delicacy_theme_setup() {

	require( get_template_directory() . '/inc/tweaks.php' );
	require( get_template_directory() . '/inc/template-tags.php' );

	load_theme_textdomain( 'delicacy', get_template_directory() . '/languages' );

	add_editor_style();

	add_theme_support( 'automatic-feed-links' );

	// Image thumbnails
	add_theme_support( 'post-thumbnails' );
	set_post_thumbnail_size( 588, 289, true );

	// Custom backgrounds support
	add_theme_support( 'custom-background', apply_filters( 'delicacy_custom_background_args', array(
		'default-color' => 'f8f8f8',
		'default-image' => get_template_directory_uri() . '/images/bg01.png',
	) ) );

	register_nav_menu( 'primary-menu', __( 'Primary Menu', 'delicacy' ) );

	add_theme_support( 'featured-content', array(
		'featured_content_filter' => 'delicacy_get_featured_posts',
		'description' => __( 'The featured content section displays on the front page above the first post in the content area.', 'delicacy' ),
		'post_types' => array( 'post', 'page' ),
		'max_posts' => 20,
	) );
}

add_action( 'after_setup_theme', 'delicacy_theme_setup' );

// JavaScript & CSS

function delicacy_styles() {
	wp_enqueue_style( 'style', get_stylesheet_uri() );

	if ( is_singular() && comments_open() && get_option( 'thread_comments' ) )
		wp_enqueue_script( 'comment-reply' );

	if ( is_front_page() && ! is_paged() && delicacy_has_featured_posts() ) {
		wp_enqueue_script(
			'delicacy-featured',
			get_template_directory_uri() . '/js/featured.js',
			array( 'jquery' ),
			'20120617'
		);
	}
}

add_action( 'wp_enqueue_scripts', 'delicacy_styles' );

// Comments
function delicacy_comments( $comment, $args, $depth ) {
	$GLOBALS['comment'] = $comment; ?>
	<li <?php comment_class(); ?> id="comment-<?php comment_ID() ?>">

		<div class="the-comment">

			<?php echo get_avatar( $comment, $size='60' ); ?>

			<div class="comment-box">

				<div class="comment-author">
					<strong><?php echo get_comment_author_link() ?></strong>
					<small><?php printf( __( '%1$s at %2$s', 'delicacy' ), get_comment_date(),  get_comment_time() ) ?><?php edit_comment_link( __( 'Edit', 'delicacy' ),'  ', '' ) ?> <?php comment_reply_link( array_merge( $args, array( 'reply_text' => 'Reply', 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?></small>
				</div>

				<div class="comment-text">
					<?php if ( $comment->comment_approved == '0' ) : ?>
					<em><?php _e( 'Your comment is awaiting moderation.', 'delicacy' ) ?></em>
					<br />
					<?php endif; ?>
					<?php comment_text() ?>
				</div>

			</div>

		</div>

<?php }

function delicacy_register_sidebars() {

	register_sidebar( array(
		'id'            => 'primary-sidebar',
		'name'          => __( 'Primary Sidebar', 'delicacy' ),
		'before_widget' => '<div id="%1$s" class="widget %2$s">',
		'after_widget'  => '</div>',
		'before_title'  => '<h3>',
		'after_title'   => '</h3>',
	) );
}

add_action( 'widgets_init', 'delicacy_register_sidebars' );

/**
 * Implement the Custom Header feature
 */
require( get_template_directory() . '/inc/custom-header.php' );

/**
 * Replaces "[...]" (appended to automatically generated excerpts) with an ellipsis.
 *
 * To override this in a child theme, remove the filter and add your own
 * function tied to the excerpt_more filter hook.
 */
function delicacy_auto_excerpt_more( $more ) {
	return ' &hellip;';
}
add_filter( 'excerpt_more', 'delicacy_auto_excerpt_more' );

function delicacy_has_featured_posts() {
	return (bool) apply_filters( 'delicacy_get_featured_posts', false );
}

function delicacy_get_featured_posts() {
	return apply_filters( 'delicacy_get_featured_posts', false );
}

/**
 * Load Jetpack compatibility file.
 */
if ( file_exists( get_template_directory() . '/inc/jetpack.php' ) )
	require get_template_directory() . '/inc/jetpack.php';