<?php

if ( ! isset( $content_width ) )
	$content_width = 700;

require_once ( get_template_directory() . '/inc/coffee-time-options.php' );

function coffeetime_scripts_styles() {
    wp_register_script( 'showhide-js', get_template_directory_uri() . '/js/showhide.js', array( 'jquery' ), false, true );
    wp_enqueue_script( 'showhide-js' );
	wp_enqueue_style( 'coffeetime', get_stylesheet_uri() );
	if ( (!is_admin()) && is_singular() && comments_open() && get_option('thread_comments') )
	wp_enqueue_script( 'comment-reply' );
	add_editor_style( 'coffeetime-editor-style.css' );
}
add_action( 'wp_enqueue_scripts', 'coffeetime_scripts_styles' );
	
function coffeetime_features()  {

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

	add_theme_support( 'automatic-feed-links' );

	$formats = array( 'status', 'quote', 'gallery', 'image', 'video', 'audio', 'link', 'aside', 'chat', );
	add_theme_support( 'post-formats', $formats );	

	add_theme_support( 'post-thumbnails' );	
	
	add_theme_support( 'html5' );

	$background_args = array(
		'default-color'          => '',
		'default-image'          => '',
		'wp-head-callback'       => '_custom_background_cb',
		'admin-head-callback'    => '',
		'admin-preview-callback' => '',
	);
	add_theme_support( 'custom-background', $background_args );

	$header_args = array(
		'default-image'          => get_template_directory_uri() . '/img/cover.jpg',
		'width'                  => 836,
		'height'                 => 836,
		'flex-width'             => false,
		'flex-height'            => false,
		'random-default'         => true,
		'header-text'            => false,
		'default-text-color'     => '',
		'uploads'                => true,

	);
	add_theme_support( 'custom-header', $header_args );
	
	
		$locations = array(
		'menuside'  => __( 'Menu on single posts', 'coffeetime' ),
		'menupage'  => __( 'Menu on pages and index', 'coffeetime' ),
	);
	register_nav_menus( $locations );
		
	add_theme_support( 'nav-menus' );
	
}
add_action( 'after_setup_theme', 'coffeetime_features' );

function coffeetime_wp_title( $title, $sep ) {
	global $paged, $page;

	if ( is_feed() )
		return $title;

	$title .= get_bloginfo( 'name' );

	$site_description = get_bloginfo( 'description', 'display' );
	if ( $site_description && ( is_home() || is_front_page() ) )
		$title = "$title $sep $site_description";

	if ( $paged >= 2 || $page >= 2 )
		$title = "$title $sep " . sprintf( __( 'Page %s', 'coffeetime' ), max( $paged, $page ) );

	return $title;
}
add_filter( 'wp_title', 'coffeetime_wp_title', 10, 2 );

function coffeetime_admin_link() {
	global $wp_admin_bar;
	$wp_admin_bar->add_menu( array( 'id' => 'ctlogo', 'title' => 'Coffee Time Options', 'href' => admin_url('themes.php?page=ctlogo')  ) ); 
}
add_action( 'admin_bar_menu', 'coffeetime_admin_link', 113 );

function coffeetime_widgets_init() {
    register_sidebar(array(
		'name'          => __( 'General Foot Widget Left', 'coffeetime' ),
		'id'            => 'coffeetime_foot1',
		'description'   => __( 'Appears in left side of footer section in pages and index.', 'coffeetime' ),
        'before_widget' => '<div class="coffeetime_widget">',
        'after_widget' => '</div>',
        'before_title' => '<strong>',
        'after_title' => '</strong> ',
));

    register_sidebar(array(
		'name'          => __( 'General Foot Widget Middle', 'coffeetime' ),
		'id'            => 'coffeetime_foot2',
		'description'   => __( 'Appears in middle of footer section in pages and index.', 'coffeetime' ),
        'before_widget' => '<div class="coffeetime_widget">',
        'after_widget' => '</div>',
        'before_title' => '<strong>',
        'after_title' => '</strong> ',
));

    register_sidebar(array(
		'name'          => __( 'General Foot Widget Right', 'coffeetime' ),
		'id'            => 'coffeetime_foot3',
		'description'   => __( 'Appears in right side of footer section in pages and index.', 'coffeetime' ),
        'before_widget' => '<div class="coffeetime_widget">',
        'after_widget' => '</div>',
        'before_title' => '<strong>',
        'after_title' => '</strong> ',
));

    register_sidebar(array(
		'name'          => __( 'Single Post Foot Widget Left', 'coffeetime' ),
		'id'            => 'coffeetime_foot4',
		'description'   => __( 'Appears only in left side of footer section in single posts.', 'coffeetime' ),
        'before_widget' => '<div class="coffeetime_widget">',
        'after_widget' => '</div>',
        'before_title' => '<strong>',
        'after_title' => '</strong> ',
));

    register_sidebar(array(
		'name'          => __( 'Single Post Foot Widget Right', 'coffeetime' ),
		'id'            => 'coffeetime_foot5',
		'description'   => __( 'Appears only in right side of footer section in single posts.', 'coffeetime' ),
        'before_widget' => '<div class="coffeetime_widget">',
        'after_widget' => '</div>',
        'before_title' => '<strong>',
        'after_title' => '</strong> ',
));

    register_sidebar(array(
		'name'          => __( 'Ad bellow titles', 'coffeetime' ),
		'id'            => 'coffeetime_ad',
		'description'   => __( 'Appears bellow the title in pages and single posts.', 'coffeetime' ),
        'before_widget' => '<div class="coffeetime_widget2">',
        'after_widget' => '</div>',
        'before_title' => '<strong>',
        'after_title' => '</strong> ',
));

    register_sidebar(array(
		'name'          => __( 'Sidebar in single posts', 'coffeetime' ),
		'id'            => 'coffeetime_sidewidget',
		'description'   => __( 'Appears bellow the author info only in single posts.', 'coffeetime' ),
        'before_widget' => '<div class="coffeetime_widget2">',
        'after_widget' => '</div>',
        'before_title' => '<strong>',
        'after_title' => '</strong> ',
));

    register_sidebar(array(
		'name'          => __( 'Hidden info', 'coffeetime' ),
		'id'            => 'coffeetime_foot-hidden',
		'description'   => __( 'Something hidden inside body tag', 'coffeetime' ),
        'before_widget' => '',
        'after_widget' => '',
        'before_title' => '',
        'after_title' => '',
));
}
add_action( 'widgets_init', 'coffeetime_widgets_init' );

function coffeetime_remove_category_rel($output)
{
    $output = str_replace(' rel="category"', '', $output);
    return $output;
}
add_filter('the_category', 'coffeetime_remove_category_rel');

function coffeetime_show_post_word_count(){
ob_start();
the_content();
$content = ob_get_clean();
return sizeof(explode(" ", $content));
}
if (!function_exists('coffeetime_est_read_time')):
function coffeetime_est_read_time( $return = false) {
$wordcount = round(str_word_count(get_the_content()), -2);
$minutes_fast = ceil($wordcount / 250);
$minutes_slow = ceil($wordcount / 150);
if ($wordcount <= 150) {
$output = __("< 1 ",'coffeetime');
} else {
$output = sprintf(__("%s~%s ",'coffeetime'), $minutes_fast, $minutes_slow);
}
echo $output;
}
endif;
if (!function_exists('coffeetime_est_the_content')):
function coffeetime_est_the_content( $orig ) {
return coffeetime_est_read_time(true) . "\n\n" . $orig;
}
endif;


?>
