<?php

/**
 * eyepress functions and definitions
 *
 * @link https://developer.wordpress.org/themes/basics/theme-functions/
 *
 * @package eyepress
 */

if (!defined('EYEPRESS_VERSION')) {
	// Replace the version number of the theme on each release.
	define('EYEPRESS_VERSION', '1.3.0');
}

if (!function_exists('eyepress_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 eyepress_setup()
	{
		/*
		 * Make theme available for translation.
		 * Translations can be filed in the /languages/ directory.
		 * If you're building a theme based on eyepress, use a find and replace
		 * to change 'eyepress' to the name of your theme in all the template files.
		 */
		load_theme_textdomain('eyepress', 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 https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/
		 */
		add_theme_support('post-thumbnails');
		add_image_size('recent-blog', 370, 288, true);


		// This theme uses wp_nav_menu() in one location.
		register_nav_menus(array(
			'blog-menu' => esc_html__('Blog menu', 'eyepress'),
		));

		/*
		 * 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',
		));



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

		/**
		 * Add support for core custom logo.
		 *
		 * @link https://codex.wordpress.org/Theme_Logo
		 */
		add_theme_support('custom-logo', array(
			'height'      => 50,
			'width'       => 160,
			'flex-width'  => true,
			'flex-height' => true,
		));

		add_editor_style(array('assets/css/bootstrap.css'));
	}
endif;
add_action('after_setup_theme', 'eyepress_setup');

/**
 * Set the content width in pixels, based on the theme's design and stylesheet.
 *
 * Priority 0 to make it available to lower priority callbacks.
 *
 * @global int $content_width
 */
if (!function_exists('eyepress_content_width')) :
	function eyepress_content_width()
	{
		// This variable is intended to be overruled from themes.
		// Open WPCS issue: {@link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/1043}.
		// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
		$GLOBALS['content_width'] = apply_filters('eyepress_content_width', 1170);
	}
endif;
add_action('after_setup_theme', 'eyepress_content_width', 0);

/**
 * Register widget area.
 *
 * @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
 */
if (!function_exists('eyepress_widgets_init')) :
	function eyepress_widgets_init()
	{
		register_sidebar(array(
			'name'          => esc_html__('Sidebar', 'eyepress'),
			'id'            => 'sidebar-1',
			'description'   => esc_html__('Add widgets here.', 'eyepress'),
			'before_widget' => '<section id="%1$s" class="widget %2$s">',
			'after_widget'  => '</section>',
			'before_title'  => '<h5 class="widget-title">',
			'after_title'   => '</h5>',
		));
	}
endif;
add_action('widgets_init', 'eyepress_widgets_init');

/*
 * Register eyepress custom fonts.
 */
if (!function_exists('eyepress_fonts_url')) :
	function eyepress_fonts_url()
	{
		$fonts_url = '';

		$font_families = array();
		$font_families[] = 'Poppins:wght@300;400;500;600;700;800';
		$fonts_url = 'https://fonts.googleapis.com/css2?family=' . urlencode(implode('&family=', $font_families)) . '&display=swap';

		return esc_url_raw($fonts_url);
	}
endif;

/**
 * Enqueue scripts and styles.
 */
if (!function_exists('eyepress_scripts')) :
	function eyepress_scripts()
	{
		$eyepress_grid_type = get_theme_mod('eyepress_grid_type', 'mesonry');

		//enqueue style
		wp_enqueue_style('eyepress-google-font', eyepress_fonts_url(), array(), null);
		wp_enqueue_style('et-lineicons', get_template_directory_uri() . '/assets/css/et-lineicons.css', array(), '1.0.0', 'all');
		wp_enqueue_style('material-design-iconic-font', get_template_directory_uri() . '/assets/css/material-design-iconic-font.css', array(), '1.0.0', 'all');
		wp_enqueue_style('bootstrap', get_template_directory_uri() . '/assets/css/bootstrap.min.css', array(), '5.3.6', 'all');
		wp_enqueue_style('slick.min', get_template_directory_uri() . '/assets/css/slick.min.css', array(), '1.5.9', 'all');
		wp_enqueue_style('eyepress-default', get_template_directory_uri() . '/assets/css/eyepress-default.css', array(), EYEPRESS_VERSION, 'all');
		wp_enqueue_style('eyepress-mobile-menu', get_template_directory_uri() . '/assets/css/mobile-menu.css', array(), EYEPRESS_VERSION, 'all');
		wp_enqueue_style('eyepress-style', get_stylesheet_uri());
		wp_enqueue_style('eyepress-responsive', get_template_directory_uri() . '/assets/css/responsive.css', array('eyepress-style'), EYEPRESS_VERSION, 'all');

		// RTL support: enqueue rtl.css automatically if is_rtl()
		if ( is_rtl() ) {
			wp_enqueue_style( 'eyepress-rtl', get_template_directory_uri() . '/rtl.css', array('eyepress-style'), EYEPRESS_VERSION, 'all' );
		}

		//enqueue scripts
		wp_enqueue_script('modernizr-js', get_template_directory_uri() . '/assets/js/vendor/modernizr-2.8.3.js', array(), '2.8.3', false);
		wp_enqueue_script('bootstrap-js', get_template_directory_uri() . '/assets/js/bootstrap.min.js', array('jquery'), '5.3.6', true);
		wp_enqueue_script('jquery.waypoints-js', get_template_directory_uri() . '/assets/js/jquery.waypoints.js', array('jquery'), '2.0.3', true);
		wp_enqueue_script('jquery.smooth.scrol-js', get_template_directory_uri() . '/assets/js/jquery.smooth.scrol.js', array('jquery'), '2.2.0', true);
		wp_enqueue_script('jquery.scrollup-js', get_template_directory_uri() . '/assets/js/jquery.scrollup.js', array('jquery'), '2.4.1', true);
		wp_enqueue_script('jquery.one.page.nav-js', get_template_directory_uri() . '/assets/js/jquery.one.page.nav.js', array('jquery'), '3.0.0', true);
		wp_enqueue_script('jquery.slick-js', get_template_directory_uri() . '/assets/js/jquery.slick.js', array('jquery'), '1.5.9', true);
		wp_enqueue_script('jquery-validation-plugin-js', get_template_directory_uri() . '/assets/js/jquery-validation-plugin.js', array('jquery'), '1.5.9', true);
		wp_enqueue_script('eyepress-main-js', get_template_directory_uri() . '/assets/js/main.js', array('jquery'), EYEPRESS_VERSION, true);
		wp_enqueue_script('eyepress-mobile-menu', get_template_directory_uri() . '/assets/js/mobile-menu.js', array(), EYEPRESS_VERSION, true);
		if ($eyepress_grid_type == 'mesonry') {
			wp_enqueue_script('masonry');
			wp_enqueue_script('eyepress-masonry-active', get_template_directory_uri() . '/assets/js/masonry-active.js', array('jquery'), EYEPRESS_VERSION, true);
		}

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

/**
 * 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';

/**
 * Functions which enhance the theme by hooking into WordPress.
 */
require get_template_directory() . '/inc/template-functions.php';

/**
 * Bootstrap navwalker class
 */
require get_template_directory() . '/inc/bootstrap-navwalker.php';

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

/**
 * Customizer helper function file.
 */
require get_template_directory() . '/inc/customizer-helper.php';
/**
 * Customizer pro info .
 */
require get_template_directory() . '/inc/info/class-customize.php';


/**
 * Inline style and script 
 */
require get_template_directory() . '/inc/inline-style-script.php';

/**
 * Mobile menu output
 */
if (!function_exists('eyepress_mobile_menu_output')) :
	function eyepress_mobile_menu_output()
	{
?>
		<div id="wsm-menu" class="mobile-menu-bar wsm-menu">
			<div class="container">
				<div class="mobile-topbar">
					<div class="mobile-topbar-logo">
						<?php
						if (has_custom_logo()) {
							the_custom_logo();
						} else { ?>
							<a href="<?php echo esc_url(home_url('/')); ?>" class="mobile-site-title" rel="home">
								<?php bloginfo('name'); ?>
							</a>
						<?php } ?>
					</div>
					<button id="mmenu-btn" class="menu-btn" aria-expanded="false" aria-controls="mobile-menu-panel" aria-label="<?php esc_attr_e('Open mobile menu', 'eyepress'); ?>">
						<span class="mopen" aria-hidden="true">
							<svg class="hamburger-icon" width="26" height="26" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" focusable="false">
								<path d="M3 12h18M3 6h18M3 18h18" stroke="currentColor" stroke-width="2" stroke-linecap="round" />
							</svg>
						</span>
						<span class="mclose" aria-hidden="true">
							<svg class="close-icon" width="26" height="26" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" focusable="false">
								<path d="M18 6L6 18M6 6l12 12" stroke="currentColor" stroke-width="2" stroke-linecap="round" />
							</svg>
						</span>
						<span class="sr-only"><?php esc_html_e('Menu', 'eyepress'); ?></span>
					</button>
				</div>
			</div>

			<!-- Overlay backdrop -->
			<div id="mobile-menu-overlay" class="mobile-menu-overlay" aria-hidden="true"></div>

			<!-- Slide-in menu panel -->
			<nav id="mobile-menu-panel" class="mobile-menu-panel" role="navigation" aria-label="<?php esc_attr_e('Mobile Menu', 'eyepress'); ?>" aria-hidden="true">
				<div class="mobile-panel-header">
					<div class="mobile-panel-logo">
						<?php
						if (has_custom_logo()) {
							the_custom_logo();
						} else { ?>
							<a href="<?php echo esc_url(home_url('/')); ?>" class="mobile-site-title" rel="home">
								<?php bloginfo('name'); ?>
							</a>
						<?php } ?>
					</div>
					<button id="mmenu-close-btn" class="menu-close-btn" aria-label="<?php esc_attr_e('Close mobile menu', 'eyepress'); ?>">
						<svg width="22" height="22" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" focusable="false">
							<path d="M18 6L6 18M6 6l12 12" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" />
						</svg>
					</button>
				</div>
				<div id="mobile-navigation" class="mobile-navigation">
					<?php
					wp_nav_menu(array(
						'theme_location' => 'blog-menu',
						'menu_id'        => 'wsm-menu-ul',
						'menu_class'     => 'wsm-menu-has',
						'container'      => false,
						'fallback_cb'    => 'eyepress_menu_fallback',
					));
					?>
				</div>
			</nav>
		</div>
	<?php
	}
	add_action('eyepress_mobile_menu', 'eyepress_mobile_menu_output');
endif;


if (!function_exists('eyepress_comment_form_filed_change')) :
	function eyepress_comment_form_filed_change($fields)
	{
		unset($fields['url']);
		return $fields;
	}
	add_filter('comment_form_fields', 'eyepress_comment_form_filed_change');
endif;

if (!function_exists('eyepress_pagination')) :
	function eyepress_pagination()
	{
		global $wp_query;
		$links = get_the_posts_pagination(array(
			'current' => max(1, get_query_var('paged')),
			'total' => $wp_query->max_num_pages,
			'type' => 'list',
			'mid_size' => 3,
			'prev_text'          => false,
			'next_text'          => false,
		));
		$links = str_replace("page-numbers", "pagination_num", $links);
		$links = str_replace("<ul class='pagination_num'>", "<ul>", $links);
		$links = str_replace("next pagination_num", "pagination_next", $links);
		$links = str_replace("prev pagination_num", "pagination_prev", $links);

		echo wp_kses_post($links);
	}
endif;

/**
 * Load theme about section.
 */
if (is_admin()) {
	require_once trailingslashit(get_template_directory()) . 'inc/about/class.about.php';
	require_once trailingslashit(get_template_directory()) . 'inc/about/about.php';
}

// plugin Recommended
require get_template_directory() . '/libs/plugin-recommend/plugin-recommendations.php';