<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet"
        integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.3.0/css/all.min.css"
        integrity="sha512-SzlrxWUlpfuzQ+pcUCosxcglQRNAq/DZjVsC0lE40xsADsfeQoEypE+enwcOiGjk/bSuGGKHEyjSoQ1zVisanQ=="
        crossorigin="anonymous" referrerpolicy="no-referrer" />
</head>
</html>
<?php
/**
 * Beruco functions and definitions
 */
 
define('BERUCO_DIR', get_template_directory() );
define('BERUCO_URI', get_template_directory_uri() );

function beruco_theme_support() {
	
	/* Text domain */
	load_theme_textdomain( 'beruco', BERUCO_DIR . '/languages' );
	
	// Add default posts and comments RSS feed links to head.
	add_theme_support( 'automatic-feed-links' );

	// Custom background color.
	add_theme_support(
		'custom-background',
		array(
			'default-color' => 'f5efe0',
		)
	);

	// Set content-width.
	global $content_width;
	if ( ! isset( $content_width ) ) {
		$content_width = 1140;
	}

	/*
	 * Enable support for Post Thumbnails on posts and pages.
	 */
	add_theme_support( 'post-thumbnails' );

	// Set post thumbnail size.
	set_post_thumbnail_size( 1200, 9999 );
	
	update_option( 'large_size_w', 1170 );
	update_option( 'large_size_h', 694 );
	update_option( 'large_crop', 1 );
	update_option( 'medium_size_w', 768 );
	update_option( 'medium_size_h', 456 );
	update_option( 'medium_crop', 1 );
	update_option( 'thumbnail_size_w', 80 );
	update_option( 'thumbnail_size_h', 80 );
	update_option( 'thumbnail_crop', 1 );

	// Custom logo.
	$logo_width  = 120;
	$logo_height = 90;

	// If the retina setting is active, double the recommended width and height.
	if ( get_theme_mod( 'retina_logo', false ) ) {
		$logo_width  = floor( $logo_width * 2 );
		$logo_height = floor( $logo_height * 2 );
	}

	add_theme_support(
		'custom-logo',
		array(
			'height'      => $logo_height,
			'width'       => $logo_width,
			'flex-height' => true,
			'flex-width'  => true,
		)
	);

	/*
	 * Let WordPress manage the document title.
	 */
	add_theme_support( 'title-tag' );

	/*
	 * Switch default core markup for search form, comment form, and comments
	 */
	add_theme_support(
		'html5',
		array(
			'search-form',
			'comment-form',
			'comment-list',
			'gallery',
			'caption',
			'script',
			'style',
		)
	);

	load_theme_textdomain( 'beruco' );

	// Add support for Block Styles.
	add_theme_support( 'wp-block-styles' );

	// Add support for full and wide align images.
	add_theme_support( 'align-wide' );

	// Add theme support for selective refresh for widgets.
	add_theme_support( 'customize-selective-refresh-widgets' );

	// Add support for editor styles.
	add_theme_support( 'editor-styles' );

	// Enqueue editor styles.
	add_editor_style( 'style-editor.css' );

	// Editor color palette.
	add_theme_support(
		'editor-color-palette',
		array(
			array(
				'name'  => esc_html__( 'Dark Gray', 'beruco' ),
				'slug'  => 'dark-gray',
				'color' => '#111',
			),
			array(
				'name'  => esc_html__( 'Light Gray', 'beruco' ),
				'slug'  => 'light-gray',
				'color' => '#767676',
			),
			array(
				'name'  => esc_html__( 'White', 'beruco' ),
				'slug'  => 'white',
				'color' => '#FFF',
			),
		)
	);

	// Add support for responsive embedded content.
	add_theme_support( 'responsive-embeds' );

}

add_action( 'after_setup_theme', 'beruco_theme_support' );

/**
 * REQUIRED FILES
 * Include required files.
 */
require get_template_directory() . '/inc/template-tags.php'; 

//Elements
require get_template_directory() . '/classes/class.beruco-wp-elements.php';
//Framework
require get_template_directory() . '/classes/class.beruco-wp-framework.php';

// Custom comment walker.
require get_template_directory() . '/classes/class-beruco-walker-comment.php';

if ( is_admin() ) {
	require_once ( BERUCO_DIR . '/admin/class.admin-settings.php');
}

if( !class_exists('Beruco_Theme_Option') ){
	require_once ( BERUCO_DIR . '/inc/theme-default.php');
}

/**
 * Register and Enqueue Scripts.
 */
function beruco_register_scripts() {

	$minify_css = Beruco_Wp_Elements::beruco_options("minify-css");

	if($minify_css){
		wp_enqueue_style(
			'style-min-css',
			get_template_directory_uri() . '/assets/css/theme.min.css',
			array(),
			'1.1'
		);
		
	} else {
		wp_enqueue_style( 'bootstrap-5', BERUCO_URI . '/assets/css/bootstrap.min.css', array(), '5.0.2' );
		wp_enqueue_style( 'bootstrap-icons', BERUCO_URI . '/assets/css/bootstrap-icons.css', false, '1.9.1' );
		wp_enqueue_style( 'themify-icons', get_template_directory_uri() . '/assets/css/themify-icons.css', array(), '1.0.1', 'all' );

		// Woo
		if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
			wp_enqueue_style( 'beruco-woo-style', get_theme_file_uri( '/assets/css/woo-styles.css' ), array(), '1.0' );
		}
	}

	wp_register_style( 'owl-carousel', get_template_directory_uri() . '/assets/css/owl-carousel.min.css', array(), '1.8.0', 'all' );
	$theme_version = wp_get_theme()->get( 'Version' );
	wp_enqueue_style( 'beruco-style', get_template_directory_uri() . '/style.css', array(), $theme_version );
	wp_style_add_data( 'beruco-style', 'rtl', 'replace' );	

	if( !class_exists('Beruco_Theme_Option') ){
		wp_enqueue_style( 'beruco-google-fonts', beruco_theme_default_fonts_url(), array(), null, 'all' );
		wp_enqueue_style( 'beruco-custom', BERUCO_URI . '/assets/css/theme-custom-default.css', array(), '1.0' );
	}else{
		$custom_css = '';
		$custom_style = get_option( 'beruco_custom_styles' );
		if( class_exists( 'Beruco_Theme_Option' ) ){
			if( $custom_style ){
				$custom_css .= Beruco_Theme_Option::beruco_minify_css( $custom_style );
			}else{
				$custom_css = apply_filters( 'beruco_trigger_to_save_custom_styles', $custom_css );
			}
			if( is_singular() ){
				$post_id = get_the_ID();
				$post_styles = get_post_meta( $post_id, 'beruco_post_custom_styles', true );
				if( $post_styles ){
					$custom_css .= $post_styles; //Beruco_Theme_Option::beruco_minify_css( $post_styles );
				}
			}
		}
		if( $custom_css ) wp_add_inline_style( 'beruco-style', stripslashes_deep( $custom_css ) );
	}

	$theme_version = wp_get_theme()->get( 'Version' );

	if ( ( ! is_admin() ) && is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
		wp_enqueue_script( 'comment-reply' );
	}

	$minify_js = Beruco_Wp_Elements::beruco_options("minify-js");

	if( $minify_js ){
		wp_register_script(
			'theme-min',
			get_template_directory_uri() . '/assets/js/theme.min.js',
			array(),
			'1.1'
		);
	} else {
		wp_register_script( 'owl-carousel', get_template_directory_uri() . '/assets/js/owl.carousel.min.js', array( 'jquery' ), '1.8.0', false );
	}
	wp_enqueue_script( 'beruco-js', get_template_directory_uri() . '/assets/js/theme.js', array( 'jquery' ), $theme_version, false );
	wp_script_add_data( 'beruco-js', 'async', true );

	$header_offset = Beruco_Wp_Elements::beruco_options("header-offset");
	$header_offset_y = is_array( $header_offset ) && isset( $header_offset['height'] ) ? $header_offset['height'] : 0;
	$mheader_offset = Beruco_Wp_Elements::beruco_options("mobile-header-offset");
	$mheader_offset_y = is_array( $mheader_offset ) && isset( $mheader_offset['height'] ) ? $mheader_offset['height'] : 0;
	$res_width = Beruco_Wp_Elements::beruco_options("mobilebar-responsive");

	$beruco_js_args = array(
		'ajax_url' => esc_url( admin_url('admin-ajax.php') ),
		'add_to_cart' => wp_create_nonce('beruco-add-to-cart(*$#'),
		'remove_from_cart' => wp_create_nonce('beruco-remove-from-cart(*$#'),
		'cart_update_pbm' => esc_html__('Cart Update Problem.', 'beruco'),
		'wishlist_remove' => wp_create_nonce('beruco-wishlist-{}@@%^@'),
		'product_view' => wp_create_nonce('beruco-product-view-@%^&#'),
		'mc_nounce' => wp_create_nonce( 'beruco-mailchimp' ), 
		'must_fill' => esc_html__( 'Must Fill Required Details.', 'beruco' ),
		'valid_email' => esc_html__( 'Enter Valid Email ID.', 'beruco' ),
		'header_offset' => $header_offset_y,
		'mheader_offset' => $mheader_offset_y,
		'res_width' => $res_width
	);
	$beruco_js_args = apply_filters( 'beruco_wp_localize_args', $beruco_js_args );
	wp_localize_script('beruco-js', 'beruco_ajax_var', $beruco_js_args );
}
add_action( 'wp_enqueue_scripts', 'beruco_register_scripts' );

/**
 * Enqueue supplemental block editor styles.
 */
function beruco_editor_customizer_styles() {
	if( !class_exists('Beruco_Options') ){
		require_once ( BERUCO_DIR . '/inc/theme-default.php');
		wp_enqueue_style( 'beruco-customizer-google-fonts', beruco_theme_default_fonts_url(), array(), null, 'all' );
	}
	
	$minify_css = Beruco_Wp_Elements::beruco_options("minify-css");
	if( $minify_css ){
		wp_enqueue_style(
			'style-min',
			get_template_directory_uri() . '/assets/css/style.min.css',
			array(),
			'1.1'
		);
		wp_enqueue_style( 'themify-icons', get_template_directory_uri() . '/assets/css/themify-icons.css', array(), '1.0.1', 'all' );
		wp_enqueue_style( 'beruco-editor-customizer-styles', get_theme_file_uri( '/style-editor-customizer.css' ), false, '1.0', 'all' );	
	} else {
		wp_enqueue_style( 'themify-icons', get_template_directory_uri() . '/assets/css/themify-icons.css', array(), '1.0.1', 'all' );
		wp_enqueue_style( 'beruco-editor-customizer-styles', get_theme_file_uri( '/style-editor-customizer.css' ), false, '1.0', 'all' );	
	}
	wp_enqueue_style( 'bootstrap-icons', BERUCO_URI . '/assets/css/bootstrap-icons.css', false, '1.9.1' );

	if( class_exists('Beruco_Options') ){
		ob_start();
		require_once ( BERUCO_ADDON_DIR . '/admin/extension/theme-options/theme-editor-css.php');
		$custom_styles = ob_get_clean();
		wp_add_inline_style( 'beruco-editor-customizer-styles', $custom_styles );
		add_action( 'admin_head', function(){ Beruco_Wp_Actions::beruco_google_fonts_con(); }, 10 );
	}
}
add_action( 'enqueue_block_editor_assets', 'beruco_editor_customizer_styles' );

/**
 * Register navigation menus uses wp_nav_menu in five places.
 */
function beruco_menus() {

	$locations = array(
		'primary'  => __( 'Primary Menu', 'beruco' ),
		'mobile'   => __( 'Mobile Menu', 'beruco' ),
		'top-menu'  => __( 'Top Menu', 'beruco' ),
		'footer'   => __( 'Footer Menu', 'beruco' )
	);

	register_nav_menus( $locations );
}
add_action( 'init', 'beruco_menus' );

function increase_upload_size_limit( $upload_size_limit ) {
    // Set the maximum upload file size to 10MB (in bytes)
    return 10 * 1024 * 1024; 
}
add_filter( 'upload_size_limit', 'increase_upload_size_limit' );

/**
 * Register widget areas.
 */
function beruco_sidebar_registration() {

	// Arguments used in all register_sidebar() calls.
	$shared_args = array(
		'before_title'  => '<h3 class="widget-title subheading heading-size-3">',
		'after_title'   => '</h3>',
		'before_widget' => '<div class="widget %2$s"><div class="widget-content">',
		'after_widget'  => '</div></div>',
	);

	// Right Sidebar
	register_sidebar(
		array_merge(
			$shared_args,
			array(
				'name'        => esc_html__( 'Right Sidebar', 'beruco' ),
				'id'          => 'right-sidebar',
				'description' => esc_html__( 'Widgets in this area will be displayed in the right side column in the content area.', 'beruco' ),
			)
		)
	);
	
	// Footer #1.
	register_sidebar(
		array_merge(
			$shared_args,
			array(
				'name'        => esc_html__( 'Footer #1', 'beruco' ),
				'id'          => 'footer-1',
				'description' => esc_html__( 'Widgets in this area will be displayed in the first column in the footer.', 'beruco' ),
			)
		)
	);

	// Footer #2
	register_sidebar(
		array_merge(
			$shared_args,
			array(
				'name'        => esc_html__( 'Footer #2', 'beruco' ),
				'id'          => 'footer-2',
				'description' => esc_html__( 'Widgets in this area will be displayed in the second column in the footer.', 'beruco' ),
			)
		)
	);

	// Footer #3
	register_sidebar(
		array_merge(
			$shared_args,
			array(
				'name'        => esc_html__( 'Footer #3', 'beruco' ),
				'id'          => 'footer-3',
				'description' => esc_html__( 'Widgets in this area will be displayed in the third column in the footer.', 'beruco' ),
			)
		)
	);
	
	// Footer #4
	register_sidebar(
		array_merge(
			$shared_args,
			array(
				'name'        => esc_html__( 'Footer #4', 'beruco' ),
				'id'          => 'footer-4',
				'description' => esc_html__( 'Widgets in this area will be displayed in the third column in the footer.', 'beruco' ),
			)
		)
	);

}

add_action( 'widgets_init', 'beruco_sidebar_registration' );

/**
 * Overwrite default more tag with styling and screen reader markup.
 *
 * @param string $html The default output HTML for the more tag.
 *
 * @return string $html
 */
function beruco_read_more_tag( $html ) {
	return preg_replace( '/<a(.*)>(.*)<\/a>/iU', sprintf( '<div class="read-more-button-wrap"><a$1><span class="faux-button">$2</span> <span class="screen-reader-text">"%1$s"</span></a></div>', get_the_title( get_the_ID() ) ), $html );
}
add_filter( 'the_content_more_link', 'beruco_read_more_tag' );

//Excerpt more
add_filter( 'excerpt_more', function($length) {
    return '..';
} );

// Add the custom columns to the book post type:
add_filter( 'manage_posts_columns', 'beruco_set_custom_edit_columns' );
add_filter( 'manage_pages_columns', 'beruco_set_custom_edit_columns' );
function beruco_set_custom_edit_columns( $columns ) {
	unset( $columns['author'] );
    $columns['views'] = __( 'Views', 'beruco' );
    return $columns;
}

// Add the data to the custom columns for the book post type:
add_action( 'manage_posts_custom_column' , 'beruco_custom_post_column', 10, 2 );
add_action( 'manage_pages_custom_column' , 'beruco_custom_post_column', 10, 2 );
function beruco_custom_post_column( $column, $post_id ) {
	switch ( $column ) {
		case 'views' :
			echo get_post_meta( $post_id , 'beruco_post_views_count' , true ); 
		break;
    }
}

// Beruco Mobile Header
add_action( 'beruco_header_before', 'beruco_mobile_header', 10 );
function beruco_mobile_header(){
	get_template_part( 'template-parts/mobile', 'header' );
}

// Beruco Header
add_action( 'beruco_header', 'beruco_desktop_header', 10 );
function beruco_desktop_header(){
	get_template_part( 'template-parts/site', 'header' );
}

// Header slider action 
add_action( 'beruco_header_after', 'beruco_header_slider', 10 );
function beruco_header_slider(){	
	$page_options = Beruco_Wp_Elements::$beruco_page_options;	
	if( !empty( $page_options ) && is_array( $page_options ) ):
		if( isset( $page_options['header-slider'] ) && !empty( $page_options['header-slider'] ) ? sanitize_text_field( $page_options['header-slider'] ) : '' ){
			echo '<div class="beruco-slider-wrapper">';
				echo do_shortcode( $page_options['header-slider'] );
			echo '</div> <!-- .beruco-slider-wrapper -->';
		}
	endif;
}

add_action( 'beruco_footer', 'beruco_site_footer', 10 );
function beruco_site_footer(){
	get_template_part( 'template-parts/site', 'footer' );
}

//Default exceprt length
if( !class_exists( 'Beruco_Addon' ) ){
	add_filter( 'excerpt_length', 'beruco_default_excerpt_length', 10 );
	function beruco_default_excerpt_length( $length ){
		$beruco_options = get_option( 'beruco_options' );
		if( isset( $beruco_options['blog-post-excerpt-length'] ) && !empty( $beruco_options['blog-post-excerpt-length'] ) ) {
			return absint( $beruco_options['blog-post-excerpt-length'] );
		}
		return $length;
	}
}
