<?php
/**
 * sister functions and definitions
 *
 * @package sister
 */

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

if ( ! function_exists( 'sister_setup' ) ) :
/**
 * Sets up theme defaults and registers support for various WordPress features.
 *
 * Note that this function is hooked into the after_setup_theme hook, which
 * runs before the init hook. The init hook is too late for some features, such
 * as indicating support for post thumbnails.
 */
function sister_setup() {

	/*
	 * Make theme available for translation.
	 * Translations can be filed in the /languages/ directory.
	 * If you're building a theme based on sister, use a find and replace
	 * to change 'sister' to the name of your theme in all the template files
	 */
	load_theme_textdomain( 'sister', get_template_directory() . '/languages' );

	// Add default posts and comments RSS feed links to head.
	add_theme_support( 'automatic-feed-links' );

	/*
	 * Let WordPress manage the document title.
	 * By adding theme support, we declare that this theme does not use a
	 * hard-coded <title> tag in the document head, and expect WordPress to
	 * provide it for us.
	 */
	add_theme_support( 'title-tag' );

	/*
	 * Enable support for Post Thumbnails on posts and pages.
	 *
	 * @link http://codex.wordpress.org/Function_Reference/add_theme_support#Post_Thumbnails
	 */
	add_theme_support( 'post-thumbnails' );

	// This theme uses wp_nav_menu() in one location.
	register_nav_menus( array(
		'primary' => esc_html__( 'Main Menu', 'sister' ),
	) );

	/*
	 * Switch default core markup for search form, comment form, and comments
	 * to output valid HTML5.
	 */
	add_theme_support( 'html5', array(
		'search-form', 'comment-form', 'comment-list', 'gallery', 'caption',
	) );

	/*
	 * Enable support for Post Formats.
	 * See http://codex.wordpress.org/Post_Formats
	 */
	add_theme_support( 'post-formats', array(
		'aside', 'image', 'gallery', 'video', 'audio'
	) );

	// Set up the WordPress core custom background feature.
	add_theme_support( 'custom-background', apply_filters( 'sister_custom_background_args', array(
		'default-color' => 'ffffff',
		'default-image' => '',
	) ) );
}
endif; // sister_setup
add_action( 'after_setup_theme', 'sister_setup' );

/**
 * Register widget area.
 *
 * @link http://codex.wordpress.org/Function_Reference/register_sidebar
 */
function sister_widgets_init() {
	register_sidebar( array(
		'name'          => esc_html__( 'Sidebar', 'sister' ),
		'id'            => 'sidebar-1',
		'description'   => '',
		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
		'after_widget'  => '</aside>',
		'before_title'  => '<h2 class="widget-title">',
		'after_title'   => '</h2>',
	) );

	register_sidebar( array(
		'name'          => esc_html__( 'Top Bar Area for Social Icons', 'sister' ),
		'id'            => 'sidebar-top',
		'description'   => 'Move here the widget Social Links (sister) and delete the title Social Links. Each Social Links should have http://',
		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
		'after_widget'  => '</aside>',
		'before_title'  => '<h2 class="widget-title">',
		'after_title'   => '</h2>',
	) );

	register_sidebar( array(
		'name'          => esc_html__( 'Footer Column 1', 'sister' ),
		'id'            => 'footer-column-1',
		'description'   => 'Sidebar Footer Column 1',
		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
		'after_widget'  => '</aside>',
		'before_title'  => '<h2 class="widget-title">',
		'after_title'   => '</h2>',
	) );

	register_sidebar( array(
		'name'          => esc_html__( 'Footer Column 2', 'sister' ),
		'id'            => 'footer-column-2',
		'description'   => 'Sidebar Footer Column 2',
		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
		'after_widget'  => '</aside>',
		'before_title'  => '<h2 class="widget-title">',
		'after_title'   => '</h2>',
	) );

	register_sidebar( array(
		'name'          => esc_html__( 'Footer Column 3', 'sister' ),
		'id'            => 'footer-column-3',
		'description'   => 'Sidebar Footer Column 3',
		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
		'after_widget'  => '</aside>',
		'before_title'  => '<h2 class="widget-title">',
		'after_title'   => '</h2>',
	) );
}
add_action( 'widgets_init', 'sister_widgets_init' );

/**
 * Custom Editor Style
 *
 */
function sister_add_editor_styles() {
    add_editor_style( 'editor-style.css' );
}
add_action( 'init', 'sister_add_editor_styles' );

/**
 * Add Featured Posts
 *
 */
function sister_get_featured_posts() {
    return apply_filters( 'sister_get_featured_posts', array() );
}

function sister_has_featured_posts( $minimum = 1 ) {
    if ( is_paged() )
        return false;
 
    $minimum = absint( $minimum );
    $featured_posts = apply_filters( 'sister_get_featured_posts', array() );
 
    if ( ! is_array( $featured_posts ) )
        return false;
 
    if ( $minimum > count( $featured_posts ) )
        return false;
 
    return true;
}

/**
 * Enqueue scripts and styles.
 */
function sister_scripts() {

	wp_enqueue_style( 'sister-style', get_stylesheet_uri() );
	wp_style_add_data( 'sister-style', 'rtl', 'replace' );

    wp_enqueue_style( 'fontawesome', get_template_directory_uri() . '/css/font-awesome.css' );

	wp_enqueue_script( 'sister-imageloaded', get_template_directory_uri() . '/js/imagesloaded.pkgd.min.js', array('jquery'), '4.1.3', true );
	wp_enqueue_script( 'sister-navigation', get_template_directory_uri() . '/js/navigation.js', array('jquery'), '20120206', true );
	wp_enqueue_script( 'sister-sticky', get_template_directory_uri() . '/js/jquery.sticky.js', array('jquery'), '1.0.4', true );
	wp_enqueue_script( 'sister-fitvids', get_template_directory_uri() . '/js/jquery.fitvids.js', array('jquery'), '1.1.0', true );
	wp_enqueue_script( 'sister-scripts', get_template_directory_uri() . '/js/scripts.js', array('jquery'), '20130115', true );

	if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
		wp_enqueue_script( 'comment-reply' );
	}
}
add_action( 'wp_enqueue_scripts', 'sister_scripts' );

/**
 * Add notice after active theme.
 */
function sister_notice() {
	global $pagenow;
	if ( is_admin() && isset( $_GET['activated'] ) && 'themes.php' === $pagenow ) {
	?>
	<div class="updated notice notice-success is-dismissible">
		<p>
			<?php
			// Translators: welcome page.
			echo wp_kses_post( sprintf( __( 'Thank you for choosing Sister. To get started, visit our <a href="%s">welcome page</a>.', 'sister' ), esc_url( admin_url( 'themes.php?page=sister' ) ) ) );
			?>
		</p>
		<p>
			<a class="button" href="<?php echo esc_url( admin_url( 'themes.php?page=sister' ) ); ?>"><?php esc_html_e( 'Get started with Sister', 'sister' ); ?></a>
		</p>
	</div>
	<?php
	}
}
add_action( 'admin_notices', 'sister_notice' );

/**
 * Load dashboard
 */
require get_template_directory() . '/inc/dashboard/class-hs-dashboard.php';
$dashboard = new Sister_Dashboard;

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

/**
 * Custom template tags for this theme.
 */
require get_template_directory() . '/inc/template-tags.php';

/**
 * Custom functions that act independently of the theme templates.
 */
require get_template_directory() . '/inc/extras.php';

/**
 * Customizer additions.
 */
require get_template_directory() . '/inc/customizer.php';

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

/**
 * Add "pro" link to the customizer
 *
 */
require get_template_directory() . '/inc/customize-pro/class-customize.php';

/**
 * Add Google Fonts
 */
function sister_add_google_fonts() {

wp_register_style('googleFonts', 'http://fonts.googleapis.com/css?family=Dancing+Script:400,700|Lato:400,700|Open+Sans:400,700|Quattrocento+Sans:400,700');
	wp_enqueue_style( 'googleFonts');
}
add_action('wp_print_styles', 'sister_add_google_fonts');

/**
 * Tag Cloud Sizes
 */
function sister_set_tag_cloud_sizes($args) {
	$args['smallest'] = 8;
	$args['largest'] = 18;
return $args; 
}
add_filter('widget_tag_cloud_args','sister_set_tag_cloud_sizes');

/**
 * Add to scroll top
 */
function sister_scroll_to_top() {
?>
<a href="#top" class="smoothup" title="Back to top"><i class="fa fa-arrow-circle-up fa-2x" aria-hidden="true"></i>
</a>
<?php
}
add_action('wp_footer', 'sister_scroll_to_top');

/**
 * Custom Comments
 */
function sister_comment($comment, $args, $depth) {
    if ( 'div' === $args['style'] ) {
        $tag       = 'div';
        $add_below = 'comment';
    } else {
        $tag       = 'li';
        $add_below = 'div-comment';
    }?>
    <<?php echo $tag; ?> <?php comment_class( empty( $args['has_children'] ) ? '' : 'parent' ); ?> id="comment-<?php comment_ID() ?>"><?php 
    if ( 'div' != $args['style'] ) { ?>
        <div id="div-comment-<?php comment_ID() ?>" class="comment-body"><?php
    } ?>
        <div class="comment-author vcard"><?php 
            if ( $args['avatar_size'] != 0 ) {
                echo get_avatar( $comment, $args['avatar_size'] ); 
            } 
            printf( __( '<cite class="fn">%s</cite> <span class="says">says:</span>', 'sister' ), get_comment_author_link() ); ?>
        </div><?php 
        if ( $comment->comment_approved == '0' ) { ?>
            <em class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.', 'sister' ); ?></em><br/><?php 
        } ?>
        <div class="comment-meta commentmetadata">
            <a href="<?php echo htmlspecialchars( get_comment_link( $comment->comment_ID ) ); ?>"><?php
                /* translators: 1: date, 2: time */
                printf( 
                    __('%1$s at %2$s', 'sister'), 
                    get_comment_date(),  
                    get_comment_time() 
                ); ?>
            </a><?php 
            edit_comment_link( __( '(Edit)', 'sister' ), '  ', '' ); ?>
        </div>

        <div class="comment-content"><?php comment_text(); ?></div>

        <div class="reply"><?php 
                comment_reply_link( 
                    array_merge( 
                        $args, 
                        array( 
                            'add_below' => $add_below, 
                            'depth'     => $depth, 
                            'max_depth' => $args['max_depth'] 
                        ) 
                    ) 
                ); ?>
        </div><?php 
    if ( 'div' != $args['style'] ) : ?>
        </div><?php 
    endif;
}

/**
 * Returns a "Read more" link for excerpts
 *
 */
function sister_excerpt_more( $more ) {
	if (is_admin()) return $more;
	return sprintf('<a class="more-link button" href="%1$s">%2$s</a>', get_permalink(get_the_ID()) , __('Read More', 'sister'));
}
add_filter( 'excerpt_more', 'sister_excerpt_more' );