<?php
/**
 * TechLauncher functions and definitions.
 *
 * @package techlauncher
 */

$techlauncher_theme_path = get_template_directory() . '/inc/';

// Include required files
require($techlauncher_theme_path . '/custom-navwalker.php');
require($techlauncher_theme_path . '/font/font.php');
require($techlauncher_theme_path .'/enqueue.php');
require($techlauncher_theme_path . '/customize/customize_control/class-customize-alpha-color-control.php');
require($techlauncher_theme_path . '/customize/customize_copyright.php');

if (!function_exists('techlauncher_setup')) :
    /**
     * Sets up theme defaults and registers support for various WordPress features.
     */
    function techlauncher_setup() {
        load_theme_textdomain('techlauncher', get_template_directory() . '/languages');
        add_theme_support('automatic-feed-links');
        add_theme_support('title-tag');
        add_theme_support('post-thumbnails');
        register_nav_menus(array(
            'primary' => __('Primary menu', 'techlauncher')
        ));
        add_theme_support('html5', array(
            'comment-form', 'comment-list', 'gallery', 'caption', 'style', 'script', 'search-form', 'navigation-widgets',
        ));
        add_theme_support('custom-logo');
        add_theme_support('custom-background', apply_filters('techlauncher_custom_background_args', array(
            'default-color' => 'eeeeee', 'default-image' => '',
        )));
        add_theme_support('custom-header');
        add_editor_style();
    }
endif;
add_action('after_setup_theme', 'techlauncher_setup');

function techlauncher_content_width() {
    $GLOBALS['content_width'] = apply_filters('techlauncher_content_width', 640);
}
add_action('after_setup_theme', 'techlauncher_content_width', 0);

function techlauncher_widgets_init() {
    register_sidebar(array(
        'name' => esc_html__('Sidebar', 'techlauncher'),
        'id' => 'sidebar-1',
        'before_widget' => '<div id="%1$s" class="TL-widget %2$s">',
        'after_widget' => '</div>',
        'before_title' => '<h6>',
        'after_title' => '</h6>',
    ));
    register_sidebar(array(
        'name' => esc_html__('Footer Widget Area', 'techlauncher'),
        'id' => 'footer_widget_area',
        'before_widget' => '<div id="%1$s" class="col-md-6 col-sm-6 TL-widget %2$s">',
        'after_widget' => '</div>',
        'before_title' => '<h6>',
        'after_title' => '</h6>',
    ));
}
add_action('widgets_init', 'techlauncher_widgets_init');

function techlauncher_enqueue_customizer_controls_styles() {
    wp_register_style('techlauncher-customizer-controls', get_template_directory_uri() . '/css/customizer-controls.css', NULL, NULL, 'all');
    wp_enqueue_style('techlauncher-customizer-controls');
}
add_action('customize_controls_print_styles', 'techlauncher_enqueue_customizer_controls_styles');

function techlauncher_read_more() {
    if (!is_admin()) {
        global $post;
        return '<br><a class="btn btn-tislider-two" href="' . esc_url(get_permalink()) . '">'.__('Read More','techlauncher').'</a>';
    }
}
add_filter('the_content_more_link', 'techlauncher_read_more');

function techlauncher_excerpt_more($more) {
    if (is_admin()) {
        return $more;
    }
    global $post;
    return ' ...<br><div class="Read-more-div"><a class="Read-more-button" href="'. esc_url(get_permalink($post->ID)) . '">' . __('Continue Reading &raquo;','techlauncher') . '</a></div>';
}
add_filter('excerpt_more', 'techlauncher_excerpt_more');

function techlauncher_pingback_header() {
    if (is_singular() && pings_open()) {
        echo '<link rel="pingback" href="' . esc_url(get_bloginfo('pingback_url')) . '">';
    }
}
add_action('wp_head', 'techlauncher_pingback_header');

add_action('after_setup_theme', function() {
    add_theme_support('wp-block-styles');
    add_theme_support('responsive-embeds');
    add_theme_support('align-wide');
});

function techlauncher_social_links() {
    $facebook_profile = get_the_author_meta('facebook_profile');
    if ($facebook_profile && $facebook_profile != '') {
        echo '<li class="facebook"><a href="' . esc_url($facebook_profile) . '"><i class="fa fa-facebook-square"></i></a></li>';
    }

    $twitter_profile = get_the_author_meta('twitter_profile');
    if ($twitter_profile && $twitter_profile != '') {
        echo '<li class="twitter"><a href="' . esc_url($twitter_profile) . '"><i class="fa fa-twitter-square"></i></a></li>';
    }

    $google_profile = get_the_author_meta('google_profile');
    if ($google_profile && $google_profile != '') {
        echo '<li class="googleplus"><a href="' . esc_url($google_profile) . '" rel="author"><i class="fa fa-google-plus-square"></i></a></li>';
    }

    $linkedin_profile = get_the_author_meta('linkedin_profile');
    if ($linkedin_profile && $linkedin_profile != '') {
        echo '<li class="linkedin"><a href="' . esc_url($linkedin_profile) . '"><i class="fa fa-linkedin-square"></i></a></li>';
    }
}

function techlauncher_display_social_links() {
    $social_links = array(
        'facebook' => get_theme_mod('social_link_facebook'),
        'twitter' => get_theme_mod('social_link_twitter'),
        'linkedin' => get_theme_mod('social_link_linkedin'),
        'google' => get_theme_mod('social_link_google'),
    );

    foreach ($social_links as $key => $link) {
        if ($link) {
            $new_tab = get_theme_mod('Social_link_' . $key . '_tab') ? 'target="_blank"' : '';
            echo '<li><span class="icon-soci"><a href="' . esc_url($link) . '" ' . $new_tab . '><i class="fa fa-' . $key . '"></i></a></span></li>';
        }
    }
}

if ( ! function_exists( 'wp_body_open' ) ) {
    /**
     * Backward compatibility for wp_body_open().
     */
    function wp_body_open() {
        do_action( 'wp_body_open' );
    }
}
