<?php
/**
 * Custom template tags for this theme
 *
 * Eventually, some of the functionality here could be replaced by core features.
 *
 * @package nbcore
 */

function aidoo_get_header()
{

    $header_style = aidoo_get_options('nbcore_header_style');

    get_template_part('template-parts/headers/' . $header_style);
}

function aidoo_main_nav()
{
    $admin_url = get_admin_url() . 'customize.php?url=' . get_permalink() . '&autofocus%5Bsection%5D=menu_locations';

    if (has_nav_menu('primary')) {
        echo '<nav class="main-navigation" role="navigation">';
        echo '<button class="mobile-toggle-button icon-menu1"></button>';
        echo '<div class="menu-main-menu-wrap">';
        echo '<div class="menu-main-menu-title"><h3>' . esc_html__('Navigation', 'aidoo') . '</h3><span class="icon-cancel-circle"></span></div>';
        wp_nav_menu(array(
            'theme_location' => 'primary',
            'menu_class' => 'nb-navbar',
            'link_before' => '<span>',
            'link_after' => '</span>',
        ));

        echo '</div></nav>';
    }
}

function aidoo_sub_menu()
{
    $admin_url = get_admin_url() . 'customize.php?url=' . get_permalink() . '&autofocus%5Bsection%5D=menu_locations';

    if (has_nav_menu('header-sub')) {
        echo '<nav class="sub-navigation" role="navigation">';

        wp_nav_menu(array(
            'theme_location' => 'header-sub',
            'menu_class' => 'nb-header-sub-menu',
            'link_before' => '<span>',
            'link_after' => '</span>',
        ));

        if(class_exists( 'Alg_WC_Currency_Switcher' )){
            if(is_active_sidebar('currency-switcher')){
                dynamic_sidebar('currency-switcher');
            }
        }

        echo '</nav>';
    } else {
        echo '<a class="assign-sub-menu" href="#"></a>';
    }
}

function aidoo_get_nav_mobile()
{
    if (has_nav_menu('primary')) {
        echo '<nav class="main-mobile-navigation" role="navigation">';

        echo '<button class="mobile-toggle-button icon-menu1"></button>';

        wp_nav_menu(array(
            'theme_location' => 'primary',
            'menu_class' => 'nb-mobile-navbar',
            'link_before' => '<span>',
            'link_after' => '</span>',
        ));

        echo '</nav>';
    }
}

function aidoo_header_class()
{
    $classes = array();

    $classes['header_style'] = aidoo_get_options('nbcore_header_style');

    if (aidoo_get_options('nbcore_header_fixed')) {
        $classes['header_fixed'] = 'fixed';
    }

    if(aidoo_get_options('nbcore_main_menu_customize')){
        $classes['header_customize'] = 'enable';
    }

    echo implode(' ', $classes);
}

function aidoo_header_woo_section($account = TRUE)
{

        $header_style = aidoo_get_options('nbcore_header_style');

        if (in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_option('active_plugins')))) {
            if ($account): ?>
                <div class="header-account-wrap">
                    <?php if (is_user_logged_in()):
                        if ('left-inline' == $header_style):?>
                            <i class="icon-user-o"></i>
                        <?php else: ?>
                            <span class="account-text"><?php esc_html_e('My Account', 'aidoo'); ?></span>
                        <?php endif; ?>
                        <div class="nb-account-dropdown">
                            <?php wc_get_template('myaccount/navigation.php'); ?>
                        </div>
                    <?php else: ?>
                        <a href="<?php echo get_permalink(get_option('woocommerce_myaccount_page_id')); ?>"
                           class="not-logged-in" title="<?php esc_attr_e('Login', 'aidoo'); ?>">
                            <?php if ('left-inline' == $header_style): ?>
                                <i class="icon-text-height"></i>
                            <?php else: ?>
                                <span class="account-text"><?php esc_html_e('Login', 'aidoo'); ?></span>
                            <?php endif; ?>
                        </a>
                    <?php endif; ?>
                </div>
            <?php endif; ?>
            <div class="header-cart-wrap">
                <a class="nb-cart-section" href="<?php echo wc_get_cart_url(); ?>"
                   title="<?php esc_attr_e('View cart', 'aidoo'); ?>">
                    <i class="icon-bag"></i>
                    <span class="count-item"><?php echo WC()->cart->get_cart_contents_count(); ?></span>
                </a>
                <div class="mini-cart-section">
                    <div class="mini-cart-wrap">
                        <?php woocommerce_mini_cart(); ?>
                    </div>
                </div>
            </div>
        <?php }
    
  
}

function aidoo_search_section($popup = true)
{

    $core_settings = get_option('solutions_core_settings');
    if( ! empty($core_settings) && is_array($core_settings) && in_array('ajax-search', $core_settings) ){
        echo do_shortcode('[nbt_search]');
    }
    else{
        echo '<div class="header-search-wrap">';
    if ($popup) {
        echo '<a class="icon-header-search popup-search" href=".wrap-nbt-search-wrap" data-rel="prettyPhoto" target="_self"><i class="icon-magnifying-glass"></i></a>';
        echo '<div class="wrap-nbt-search-wrap"><div class="nbt-search-wrap">';
    }
    get_search_form();
    if ($popup) {
        echo '</div></div>';
    }
    echo '</div>';
    }
    
}

function aidoo_get_site_logo()
{
    $logo = aidoo_get_options('nbcore_logo_upload');
    if ($logo) {
        $output = '<div class="main-logo img-logo">';
        $output .= '<a href="' . esc_url(home_url('/')) . '" title="' . get_bloginfo('description') . '">';
        $output .= '<img src="' . aidoo_get_options('nbcore_logo_upload') . '" alt="' . esc_attr(get_bloginfo('name', 'display')) . '">';
        $output .= '</a>';
        $output .= '</div>';
    } else {
        $output = '<div class="main-logo text-logo">';
        $output .= '<a href="' . esc_url(home_url('/')) . '" title="' . get_bloginfo('description') . '">';
        $output .= get_bloginfo('name');
        $output .= '</a>';
        $output .= '</div>';
    }
    echo wp_kses_post( $output );
}

function aidoo_featured_thumb()
{
    $blog_layout = aidoo_get_options('nbcore_blog_archive_layout');
    if (has_post_thumbnail()):
        if ('classic' == $blog_layout) {
            $thumb = wp_get_attachment_image_src(get_post_thumbnail_id(), 'full');
        } else {
            $thumb = wp_get_attachment_image_src(get_post_thumbnail_id(), 'nbcore-masonry');
        }
    endif;

        if ('classic' === $blog_layout):
            ?>
            <div class="entry-image">
                <a href="<?php the_permalink(); ?>">
                    <?php
                    if(isset($thumb[0])):
                        echo '<div class="bg_thumb" style="background-image:url('.esc_url($thumb[0]).')"></div>';
                    endif;
                    ?>
                </a>
            </div>
        <?php else: ?>
            <div class="entry-image">
                <?php
                    if(isset($thumb[0])):
                        echo '<div class="bg_thumb" style="background-image:url('.esc_url($thumb[0]).')"></div>';
                    endif;
                ?>
                <?php if(is_archive() && aidoo_get_options('nbcore_blog_meta_view')) {?>
                <div class="image-mask">
                    <div class="wrap-count">
                        <div class="view"><i class="icon-opened-eye-1"></i><?php echo aidoo_getPostViews(get_the_ID()); ?></div>
                        <div class="comment"><i class="icon-speech-bubble"></i><?php echo get_comments_number(); ?></div>
                    </div>
                </div>
                <?php }else{ ?>
                <div class="image-mask">
                    <a href="<?php the_permalink(); ?>"><span><?php esc_html_e('View post &rarr;', 'aidoo'); ?></span></a>
                    <?php
                    $post = get_post();
                    $words = str_word_count(strip_tags($post->post_content));
                    $minutes = floor($words / 180);
                    if (1 < $minutes) {
                        $estimated_time = $minutes . esc_html__(' minutes read', 'aidoo');
                    } else {
                        $estimated_time = esc_html__('1 minute read', 'aidoo');
                    }
                    echo '<div class="read-time"> ' . $estimated_time . '</div>';
                    ?>
                </div>
                <?php } ?>
            </div>
        <?php endif;
}

/**
 * Prints HTML with meta information for the current post-date/time and author.
 */
function aidoo_posted_on()
{
    $html = '';

    if (is_single()) {
        $recent_posts = wp_get_recent_posts();
        $display_name='';
        foreach( $recent_posts as $recent ){
            $user_id = get_user_by( 'ID', $recent["post_author"] );
            $display_name = $user_id->display_name;
        }
        $date= get_the_date('F n Y');
        $html .= '<span class="post-author"><i class="icon-user"></i>' . esc_html($display_name) . '</span>'
                .'<span class="post-date"><i class="icon-calendar-empty"></i>' . $date . '</span>'
                .'<span class="post-comment"><i class="icon-comment"></i>' . get_comments_number() . '</span>';
        
        
    }
    else{
        if (!is_single()) {
            if (aidoo_get_options('nbcore_blog_meta_author')) {
                $byline = sprintf(
                    esc_html_x('%s', 'post author', 'aidoo'),
                    '<span class="author vcard"><a class="url fn n" href="' . esc_url(get_author_posts_url(get_the_author_meta('ID'))) . '">' . esc_html(get_the_author()) . '</a></span>'
                );
                $html .= '<span class="byline"><i class="icon-user"></i>By: ' . $byline . '</span>';
            }
        }
    
        if (aidoo_get_options('nbcore_blog_meta_date')) {
            $time_string = '<time class="entry-date published updated" datetime="%1$s">%2$s</time>';
            if (get_the_time('U') !== get_the_modified_time('U')) {
                $time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time><time class="updated" datetime="%3$s">%4$s</time>';
            }
    
            $time_string = sprintf($time_string,
                esc_attr(get_the_date('c')),
                esc_html(get_the_date()),
                esc_attr(get_the_modified_date('c')),
                esc_html(get_the_modified_date())
            );
    
            $posted_on = sprintf(
                esc_html_x('%s', 'post date', 'aidoo'), $time_string);
    
            $html .= '<span class="posted-on"><i class="icon-calendar-empty"></i>' . $posted_on . '</span>';
        };
    
        if ('masonry' !== aidoo_get_options('nbcore_blog_archive_layout')) {
            if (aidoo_get_options('nbcore_blog_meta_read_time')) {
                $post = get_post();
                $words = str_word_count(strip_tags($post->post_content));
                $minutes = floor($words / 180);
                if (1 < $minutes) {
                    $estimated_time = $minutes . esc_html__(' minutes read', 'aidoo');
                } else {
                    $estimated_time = esc_html__('1 minute read', 'aidoo');
                }
    
                $html .= '<span class="read-time"> ' . $estimated_time . '</span>';
            }
        }
    }
    if ('' != $html) {
        echo '<div class="entry-meta">' . $html . '</div>';
    }
}

function aidoo_get_categories()
{
    if (aidoo_get_options('nbcore_blog_meta_category')):?>
        <div class="entry-cat">
            <?php echo get_the_category_list(', '); ?>
        </div>
    <?php endif;
}

/**
 * Prints HTML with meta information for the categories, tags and comments.
 * TODO entry-footer wrap div rearrange
 */
function aidoo_get_tags()
{
    if (aidoo_get_options('nbcore_blog_meta_tag')) {
        // Hide category and tag text for pages.
        if ('post' === get_post_type()) {
            /* translators: used between list items, there is a space after the comma */
            $tags_list = get_the_tag_list('', esc_html__(', ', 'aidoo'));
            if ($tags_list) {
                printf('<span class="tags-links icon-tags">' . esc_html__('%1$s', 'aidoo') . '</span>', $tags_list); // WPCS: XSS OK.
            }
        }
    }
}

function aidoo_get_excerpt()
{
    echo '<p class="entry-summary">';
    $limit = aidoo_get_options('nbcore_excerpt_length');
    $excerpt = wp_trim_words(get_the_excerpt(), $limit, ' [...]');
    echo esc_html($excerpt);
    echo '</p>';
}

/**
 * Returns true if a blog has more than 1 category.
 *
 * @return bool
 */
function aidoo_categorized_blog()
{
    if (false === ($all_the_cool_cats = get_transient('nbcore_categories'))) {
        // Create an array of all the categories that are attached to posts.
        $all_the_cool_cats = get_categories(array(
            'fields' => 'ids',
            'hide_empty' => 1,
            // We only need to know if there is more than one category.
            'number' => 2,
        ));

        // Count the number of categories that are attached to the posts.
        $all_the_cool_cats = count($all_the_cool_cats);

        set_transient('nbcore_categories', $all_the_cool_cats);
    }

    if ($all_the_cool_cats > 1) {
        // This blog has more than 1 category so aidoo_categorized_blog should return true.
        return true;
    } else {
        // This blog has only 1 category so aidoo_categorized_blog should return false.
        return false;
    }
}

function aidoo_paging_nav()
{
    // Don't print empty markup if there's only one page.
    if ($GLOBALS['wp_query']->max_num_pages < 2) {
        return;
    }

    $paged = get_query_var('paged') ? intval(get_query_var('paged')) : 1;
    $pagenum_link = html_entity_decode(get_pagenum_link());
    $query_args = array();
    $url_parts = explode('?', $pagenum_link);

    if (isset ($url_parts[1])) {
        wp_parse_str($url_parts[1], $query_args);
    }

    $pagenum_link = remove_query_arg(array_keys($query_args), $pagenum_link);
    $pagenum_link = trailingslashit($pagenum_link) . '%_%';

    $format = $GLOBALS['wp_rewrite']->using_index_permalinks() && !strpos($pagenum_link, 'index.php') ? 'index.php/' : '';
    $format .= $GLOBALS['wp_rewrite']->using_permalinks() ? user_trailingslashit('page/%#%', 'paged') : '?paged=%#%';

    // Set up paginated links.
    $links = paginate_links(array(
        'nbcore' => $pagenum_link,
        'format' => $format,
        'total' => $GLOBALS['wp_query']->max_num_pages,
        'current' => $paged,
        'mid_size' => 1,
        'add_args' => array_map('urlencode', $query_args),
        'prev_text' => wp_kses(__('<i class=\'icon-left-open\'></i>', 'aidoo'), array('i' => array('class' => array()))),
        'next_text' => wp_kses(__('<i class=\'icon-right-open\'></i>', 'aidoo'), array('i' => array('class' => array()))),
    ));

    if ($links) :

        ?>
        <nav class="navigation paging-navigation <?php echo aidoo_get_options('pagination_style'); ?>"
             role="navigation">
                <?php echo wp_kses($links, array(
                    'a' => array(
                        'href' => array(),
                        'class' => array()
                    ),
                    'i' => array(
                        'class' => array()
                    ),
                    'span' => array(
                        'class' => array()
                    )
                )); ?>
        </nav><!--/ .navigation -->
        <?php
    endif;
}

function aidoo_page_title()
{

    if (aidoo_get_options('show_title_section')) {
    
        if (is_home() || is_front_page()) {
            if (aidoo_get_options('home_page_title_section')) {
                echo '<div class="nb-page-title-wrap"><div class="container"><div class="nb-page-title"><h1>';
                esc_html_e('Home', 'aidoo');
                echo '</h1></div></div></div>';
            }
        }
        elseif(! is_category('blog')) {
            $show_bg_title = aidoo_get_options('nbcore_page_title_image');
            $bg_image = wp_get_attachment_image_src( $show_bg_title,'full' );
            $bg_title_change = get_post_meta(get_the_ID(), 'show_image_title', true);

            $bg_title = '';
            if($show_bg_title){
                if($bg_title_change){
                    $bg_title = $bg_title_change ;
                }else{
                    $bg_title = $bg_image[0];
                }
            }

            $bg_title_inline_css = $bg_title != '' ? ' style ="background-image: url('. esc_url($bg_title) .')"' : '';
            if(aidoo_get_options('nbcore_page_title_layout')){
                echo '<div class="container">';
            }
            
            echo '<div class="nb-page-title-wrap"' . $bg_title_inline_css . ' ><div class="container layout-content">';

            if( function_exists('is_product') && ! is_product() ) {

                echo '<h1>';

                if (function_exists('is_shop') && is_shop()) {
                    echo esc_html(aidoo_get_options('nbcore_shop_title'), 'aidoo');
                } elseif (function_exists('is_product_category') && is_product_category()) {
                    echo single_cat_title();
                } elseif (function_exists('is_product_tag') && is_product_tag()) {
                    echo single_tag_title();
                } elseif (is_post_type_archive()) {
                    post_type_archive_title();
                } elseif (is_tax()) {
                    single_term_title();
                } elseif (is_category()) {
                    echo single_cat_title('', false);
                } elseif (is_archive()) {
                    echo the_archive_title();
                } elseif (is_search()) {
                    esc_html_e('Search Results', 'aidoo');
                } else {
                    if (!is_page()) {
                        the_title();
                    } else {
                        if (get_post_meta(get_the_ID(), 'nbcore_pages_title', true)) {
                            the_title();
                        }
                        else {
                            the_title();
                        }
                    }
                }

                echo '</h1>';

            }

            

            if (function_exists('woocommerce_breadcrumb')) {
                if (aidoo_get_options('nbcore_wc_breadcrumb')) {
                    woocommerce_breadcrumb();
                }
            }
            
            echo '</div></div>';
            if(aidoo_get_options('nbcore_page_title_layout')){
                echo '</div>';
            }
        } 
    }
}

/**
 * Flush out the transients used in aidoo_categorized_blog.
 */
function aidoo_category_transient_flusher()
{
    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
        return;
    }
    // Like, beat it. Dig?
    delete_transient('nbcore_categories');
}

add_action('edit_category', 'aidoo_category_transient_flusher');
add_action('save_post', 'aidoo_category_transient_flusher');

function aidoo_default_options()
{
    return array(
        'nbcore_blog_archive_layout' => 'masonry',
        'nbcore_blog_sidebar' => 'right-sidebar',
        'nbcore_excerpt_only' => false,
        'nbcore_excerpt_length' => '35',
        'nbcore_color_scheme' => 'scheme_1',
        'nbcore_primary_color' => '#f59799',
        'nbcore_secondary_color' => '#fdd835',
        'nbcore_background_color' => '#ffffff',
        'nbcore_inner_background' => '#edf0f5',
        'nbcore_heading_color' => '#333',
        'nbcore_body_color' => '#666',
        'nbcore_link_color' => '#333',
        'nbcore_link_hover_color' => '#f59799',
        'nbcore_divider_color' => '#e4e4e4',
        'nbcore_header_style' => 'aidoo-header-1',
        'nbcore_logo_upload' => '',
        'nbcore_logo_width' => '200',
        'nbcore_logo_currency_width' => '15',
        'nbcore_menu_resp'=>'992',
        'nbcore_header_fixed' => false,
        'header_bgcolor' => '#ffffff',
        'nbcore_blog_width' => '75',
        'nbcore_blog_meta_date' => true,
        'nbcore_blog_meta_read_time' => true,
        'nbcore_blog_meta_author' => true,
        'nbcore_blog_meta_category' => true,
        'nbcore_blog_meta_tag' => true,
        'nbcore_blog_sticky_sidebar' => false,
        'nbcore_blog_meta_align' => 'left',
        'show_title_section' => true,
        'nbcore_widget_title' => false,
        'nbcore_page_title_padding' => '75',
        'nbcore_page_title_image' => '',
        'nbcore_page_title_color' => '#333',
        'font_type_scale' => 'major_third',
        'body_font_family' => 'google,Poppins',
        'body_font_size' => '16',
        'heading_font_family' => 'google,Federo',
        'heading_base_size' => '16',
        'subset_cyrillic' => false,
        'subset_greek' => false,
        'subset_vietnamese' => false,
        'nbcore_wc_breadcrumb' => true,
        'nbcore_wc_content_width' => '75',
        'nbcore_pa_swatch_style' => '',
        'nbcore_shop_title' => esc_html__('Shop', 'aidoo'),
        'nbcore_shop_action' => true,
        'nbcore_product_rating' => false,
        'nbcore_product_action_style' => 'vertical',
        'shop_upsells_products' => false,
        'nbcore_shop_sidebar' => 'right-sidebar',
        'nbcore_loop_columns' => 'four-columns',
        'nbcore_products_per_page' => '12',
        'nbcore_product_list' => 'grid-type',
        'nbcore_shop_content_width' => '75',
        'nbcore_grid_product_description' => false,
        'nbcore_enable_product_title_bold' => false,
        'nbcore_footer_bot_border_top_color' => 'rgba(255, 255, 255, 0)',
        'nbcore_footer_bot_border_bot_color' => 'rgba(255, 255, 255, 0)',
        'nbcore_pd_details_title' => true,
        'nbcore_pd_details_width' => '75',
        'nbcore_pd_details_sidebar' => 'right-sidebar',
        'nbcore_wc_sale' => 'style-1',
        'nbcore_pd_images_width' => '50',
        'nbcore_pd_thumb_pos' => 'bottom-thumb',
        'nbcore_pd_meta_layout' => 'left-images',
        'nbcore_pd_featured_autoplay' => false,
        'nbcore_info_style' => 'horizontal-tabs',
        'nbcore_reviews_form' => 'full-width',
        'nbcore_reviews_round_avatar' => true,
        'nbcore_add_cart_style' => 'style-1',
        'nbcore_pd_show_social' => true,
        'nbcore_show_related' => true,
        'nbcore_pd_related_columns' => '4',
        'nbcore_show_upsells' => false,
        'nbcore_pd_upsells_columns' => '4',
        'nbcore_upsells_limit'      => '6',
        'nbcore_pb_background' => 'rgba(255, 255, 255, 0)',
        'nbcore_pb_background_hover' => '#f59799',
        'nbcore_pb_text' => '#333333',
        'nbcore_pb_text_hover' => '#ffffff',
        'nbcore_pb_border' => '#333333',
        'nbcore_pb_border_hover' => '#f59799',
        'nbcore_pb_mask' => false,
        'nbcore_sb_background' => '#f59799',
        'nbcore_sb_background_hover' => '#f59799',
        'nbcore_sb_text' => '#ffffff',
        'nbcore_sb_text_hover' => '#ffffff',
        'nbcore_sb_border' => '#f59799',
        'nbcore_sb_border_hover' => '#f59799',
        'nbcore_button_padding' => '30',
        'nbcore_button_border_radius' => '0',
        'nbcore_button_border_width' => '1',
        'nbcore_cart_layout' => 'cart-layout-2',
        'nbcore_show_cross_sells' => false,
        'nbcore_cross_sells_per_row' => '4',
        'nbcore_cross_sells_limit' => '6',
        'home_page_title_section' => false,
        'nbcore_show_footer_top' => false,
        'nbcore_footer_top_layout' => 'layout-9',
        'nbcore_footer_top_color' => '#666',
        'nbcore_footer_top_bg' => '#edf0f5',
        'nbcore_show_footer_bot' => true,
        'nbcore_footer_bot_layout' => 'layout-9',
        'nbcore_footer_bot_color' => '#333',
        'nbcore_footer_bot_bg' => '#edf0f5',
        'nbcore_footer_abs_color' => '#edf0f5',
        'nbcore_footer_abs_bg' => '#1f1f1f',
        'nbcore_top_section_padding' => '10',
        'nbcore_middle_section_padding' => '20',
        'nbcore_bot_section_padding' => '30',
        'nbcore_header_top_bg' => '#ffffff',
        'nbcore_header_top_color' => '#333',
        'nbcore_header_top_color_hover' => '#f59799',
        'nbcore_header_middle_bg' => '#ffffff',
        'nbcore_header_middle_color' => '#333',
        'nbcore_header_middle_color_hover'=>'#f59799',
        'nbcore_header_bot_bg' => '#fff',
        'nbcore_header_bot_color' => '#333',
        'nbcore_footer_top_heading' => '#333',
        'nbcore_footer_bot_heading' => '#333',
        'nbcore_blog_archive_comments' => true,
        'nbcore_blog_archive_summary' => true,
        'nbcore_blog_archive_post_style' => 'style-1',
        'nbcore_blog_single_title_position' => 'position-1',
        'nbcore_blog_bg_single_title'=>'',
        'nbcore_blog_single_show_thumb' => true,
        'nbcore_blog_single_title_size' => '36',
        'nbcore_blog_single_show_social' => true,
        'nbcore_blog_single_show_author' => true,
        'nbcore_blog_single_show_nav' => true,
        'nbcore_blog_single_show_comments' => true,
        'nbcore_page_title_size' => '36',
        'nbcore_footer_top_padding_top' => '15',
        'nbcore_footer_top_padding_bottom' => '15',
        'nbcore_footer_bot_padding_top' => '75',
        'nbcore_footer_bot_padding_bottom' => '15',
        'nbcore_enable_colorful_widget_title' => false,
        'nbcore_footer_abs_padding' => '10',
        'share_buttons_style' => 'style-1',
        'share_buttons_position' => 'inside-content',
        'pagination_style' => 'pagination-style-2',
        'show_back_top' => true,
        'back_top_shape' => 'circle',
        'back_top_style' => 'light',
        'shop_sticky_sidebar' => false,
        'product_sticky_sidebar' => false,
        'nbcore_product_meta_align' => 'left',
        'nbcore_product_price_style' => 'default_woo',
        'nbcore_product_hover' => 'image',
        'page_thumb' => 'no-thumb',
        'nbcore_pages_sidebar' => 'no-sidebar',
        'page_content_width' => '75',
        'nbcore_blog_masonry_columns' => '2',
        'product_category_wishlist' => false,
        'product_category_quickview' => false,
        'product_category_compare'=>false,
       // 'nbcore_header_mainmn_bg' => '#fff',
        'nbcore_header_mainmn_color' => '#333',
        'nbcore_header_mainmn_head_color' => '#333333',
        'nbcore_header_mainmn_bor' => '#333',
        //'nbcore_header_mainmnhover_bg' => '#fff',
        'nbcore_header_mainmnhover_color' => '#333',
        'nbcore_header_mainmnhover_bor' => '#333',
        'heading_font_style' => '500',
        'body_font_style' => '400',
        'nbcore_footer_abs_left_content' => 'Copyright 2019 by Cmsmart',
        'nbcore_footer_abs_right_content' => '',
        'nbcore_page_fullbox' => false,
        'nbcore_page_layout' => 'full-width',
        'nbcore_page_content_width' => 60,
        'nbcore_shop_banner' => '',
        'nbcore_wc_attr'=>true,
        'nbcore_show_to_shop'=>false,
        'nbcore_container_width' => '1470',
        'nbcore_pd_enable_review_rating' => false,
        'nbcore_header_preloading' => false,
        'nbcore_header_style_preloading' => 'demo2',
        'nbcore_page_title_layout' => false,

        'nbcore_template_designer_style'=>'style1',
        'nbcore_main_menu_customize' => true,
        'nbcore_blog_display_swipper' => false,
        'nbcore_blog_meta_view' => false,
        'nbcore_header_facebook' => '',
        'nbcore_header_twitter' => '',
        'nbcore_header_linkedin' => '',
        'nbcore_header_instagram' => '',
        'nbcore_header_blog' => '',
        'nbcore_header_pinterest' => '',
        'nbcore_header_ggplus' => ''
    );
}

function aidoo_get_options($option)
{
    $result = '';
    $default = aidoo_default_options();

    if(class_exists('NBFW_Metaboxes')) {
        $meta = '';
        $global = '';

        if(is_single() || is_page()) {
            $id = get_the_ID();
            $global = get_post_meta($id, 'nbcore_global_setting', true);
            $meta = get_post_meta($id, $option, true);
            
        } elseif(is_tax() || is_category() || is_tag()) {
            $id = get_queried_object_id();
            $global = get_term_meta($id, 'nbcore_global_setting', true);
            $meta = get_term_meta($id, $option, true);
        }

        if( $meta !== '' && $global !== '') {
            $result = $meta;
        } else {
            $result = get_theme_mod($option, $default[$option]);
        }
    } else {
        $result = get_theme_mod($option, $default[$option]);
    }

    return $result;
}


function aidoo_blog_classes()
{
    $classes = array();

    $classes['sidebar'] = aidoo_get_options('nbcore_blog_sidebar');
    $classes['meta_align'] = 'meta-align-' . aidoo_get_options('nbcore_blog_meta_align');
    $classes['post_style'] = aidoo_get_options('nbcore_blog_archive_post_style');

    if ('masonry' === aidoo_get_options('nbcore_blog_archive_layout')) {
        $classes['masonry_columns'] = 'masonry-' . aidoo_get_options('nbcore_blog_masonry_columns') . '-columns';
    }


    echo implode(' ', $classes);
}

function aidoo_shop_classes()
{
    $classes = array();

    if ((is_shop() || is_product_category() || is_product_tag()) && 'list-type' !== aidoo_get_options('nbcore_product_list')) {
        $classes['shop_columns'] = aidoo_get_shop_columns_class();
    }
    if (is_tax('product_brand')) {
        $classes['shop_columns'] = aidoo_get_shop_columns_class();
    }

    $classes['meta_layout'] = aidoo_get_options('nbcore_pd_meta_layout');

    if (function_exists('is_product') && is_product()) {
        $classes['nbcore_pd_thumb_pos'] = aidoo_get_options('nbcore_pd_thumb_pos');
    }

    if ('split' === aidoo_get_options('nbcore_reviews_form')) {
        $classes['nbcore_reviews_form'] = 'split-reviews-form';
    }

    if (aidoo_get_options('nbcore_reviews_round_avatar')) {
        $classes['nbcore_round_avatar'] = 'round-reviewer-avatar';
    }

    $classes['wc_tab_style'] = aidoo_get_options('nbcore_info_style');

    if (is_product()) {
        $classes['related_columns'] = 'related-' . aidoo_get_options('nbcore_pd_related_columns') . '-columns';
        $classes['upsells_columns'] = 'upsells-' . aidoo_get_options('nbcore_pd_upsells_columns') . '-columns';
    }

    echo implode(' ', $classes);
}

add_filter('woocommerce_add_to_cart_fragments', 'aidoo_header_add_to_cart_fragment');
function aidoo_header_add_to_cart_fragment($fragments)
{
    global $woocommerce;

    ob_start();

    ?>
    <a class="nb-cart-section" href="<?php echo wc_get_cart_url(); ?>"
       title="<?php esc_attr_e('View cart', 'aidoo'); ?>">
        <i class="icon-bag"></i>
        <span class="count-item"><?php echo WC()->cart->get_cart_contents_count(); ?></span>
    </a>
    <?php

    $fragments['a.nb-cart-section'] = ob_get_clean();

    return $fragments;

}

add_filter('woocommerce_add_to_cart_fragments', 'nb_mini_cart_fragments');
function nb_mini_cart_fragments($fragments)
{

    ob_start();

    ?>
    <div class="mini-cart-wrap">
        <?php woocommerce_mini_cart(); ?>
    </div>
    <?php

    $fragments['.mini-cart-wrap'] = ob_get_clean();

    return $fragments;
}

function aidoo_back_to_top()
{
    $shape = aidoo_get_options('back_top_shape');
    $style = aidoo_get_options('back_top_style');
    echo '<div class="nb-back-to-top-wrap"><a id="back-to-top-button" class="' . esc_attr($shape) . ' ' . esc_attr($style) . '" href="#"><i class="icon-angle-up"></i></a></div>';
}

function aidoo_getPostViews($postID){
    $count_key = 'post_views_count';
    $count = get_post_meta($postID, $count_key, true);
    if($count==''){
        delete_post_meta($postID, $count_key);
        add_post_meta($postID, $count_key, '0');
        return "0";
    }
    return $count;
}

// function to count views.
function aidoo_setPostViews($postID) {
    $count_key = 'post_views_count';
    $count = get_post_meta($postID, $count_key, true);
    if($count==''){
        $count = 0;
        delete_post_meta($postID, $count_key);
        add_post_meta($postID, $count_key, '0');
    }else{
        $count++;
        update_post_meta($postID, $count_key, $count);
    }
}

function aidoo_get_shop_columns_class() {

    $temp_columns =  isset($_GET['columns']) && $_GET['columns'] != '' && is_numeric($_GET['columns']) ?  $_GET['columns'] : 0;

    switch ($temp_columns) {
        case 2:
            $temp_columns_class = 'two-columns';
            break;
        case 3:
            $temp_columns_class = 'three-columns';
            break;
        case 4:
            $temp_columns_class = 'four-columns';
            break;
        case 5:
            $temp_columns_class = 'five-columns';
            break;
        
        default:
            $temp_columns_class = 'three-columns';
    }

    if($temp_columns != 0)
        $shop_columns_class = $temp_columns_class;
    else
        $shop_columns_class = aidoo_get_options('nbcore_loop_columns');

    return $shop_columns_class;
}

function aidoo_convert_columns_class_to_number($columns_class) {

    switch ($columns_class) {
        case 'two-columns':
            $columns_number = 2;
            break;
        case 'three-columns':
            $columns_number = 3;
            break;
        case 'four-columns':
            $columns_number = 4;
            break;
        case 'five-columns':
            $columns_number = 5;
            break;
        
        default:
            $columns_number = 3;
    }

    return $columns_number;
}