<?php
/**
 * Sanitize image functions
 *
 * @package wpstream-theme
 */


if(!function_exists('wpstream_theme_sanitize_image')):
	function wpstream_theme_sanitize_image( $image, $setting ) {
		// Integer values are valid
		if ( is_int( $image ) ) {
			return $image;
		}
		
		// Array values are valid if they contain an integer
		if ( is_array( $image ) && isset( $image['id'] ) && is_int( $image['id'] ) ) {
			return $image['id'];
		}
		
		// If $image is not an ID or an array with an ID, return the setting default
		return $setting->default;
	}
endif;

/**
 * Sanitize html functions
 *
 * @package wpstream-theme
 */


if ( ! function_exists( 'wpstream_sanitize_html' ) ) :
function wpstream_sanitize_html($html) {
    $allowed_html = array(
        'div' => array(
            'class' => array(),
            'id' => array(),
            'style' => array(),
        ),
        'span' => array(
            'class' => array(),
        ),
        'input' => array(
            'type' => array(),
            'class' => array(),
            'name' => array(),
            'id' => array(),
            'autofocus' => array(),
            'placeholder' => array(),
            'value' => array(),
            'size' => array(),
        ),
        'button' => array(
            'class' => array(),
        ),
        'i' => array(
            'class' => array(),
        ),
        'a' => array(
            'href' => array(),
            'target' => array(),
            'class' => array(),
        ),
        'label' => array(
            'id' => array(),
            'for' => array(),
        ),
        'h5' => array(
            'class' => array(),
        ),
    );
    
    // Allow all text nodes
    $allowed_html['#text'] = true;
    
    return wp_kses($html, $allowed_html);
}
endif;




/**
 * dropddown for bootstrap
 *
 * @package wpstream-theme
 */


if ( ! function_exists( 'wpestream_dropdown_for_search_bootstrap' ) ) :
	function wpestream_dropdown_for_search_bootstrap( $select_name = 'search_filter' ) {
		$values = apply_filters( 'wpstream_header_search_values', array(
			'any'                  => esc_html__( 'All', 'hello-wpstream' ),
			'post'                 => esc_html__( 'Blog Post', 'hello-wpstream' ),
			)
		);

		if ( class_exists( 'WooCommerce' ) ) {
			$values = array_merge($values, [
				'products' => esc_html__( 'Products', 'hello-wpstream' ),
			]);
		}

		$return_string = wpstream_create_custom_dropdown( $values, $select_name, '', '', esc_html__( 'All', 'hello-wpstream' ) );

		return $return_string;
	}
endif;


/**
 * Helper functions
 *
 * @package wpstream-theme
 */

if ( ! function_exists( 'wpstream_sanitize_boolean_field' ) ) {
	/**
	 * Return true if the value is true, "true", 1, "1", "on", "yes".
	 * Otherwise, return false.
	 *
	 * @param $input
	 * @return mixed
	 */
	function wpstream_sanitize_boolean_field( $input ) {
		return filter_var( $input, FILTER_VALIDATE_BOOLEAN );
	}
}

if ( ! function_exists( 'wpstream_get_customizer_fonts_data' ) ) {
	/**
	 * Returns all fonts data or specific from customizer.
	 *
	 * @param $type
	 *
	 * @return array|array[]
	 */
	function wpstream_get_customizer_fonts_data( $type = 0 ) {
		static $font;

		if ( empty( $font ) ) {
			$font = array(
				// header
				'header'             => array(
					'font_family' => get_theme_mod( 'wpstream_theme_header_font_family', '' ),
					'font_weight' => get_theme_mod( 'wpstream_theme_header_font_weight', '' ),
					'font_style'  => get_theme_mod( 'wpstream_theme_header_font_style', '' ),
				),
				// transparent header
				'transparent-header' => array(
					'font_family' => get_theme_mod( 'wpstream_theme_transparent_header_font_family', '' ),
					'font_weight' => get_theme_mod( 'wpstream_theme_transparent_header_font_weight', '' ),
					'font_style'  => get_theme_mod( 'wpstream_theme_transparent_header_font_style', '' ),
				),
				// sidebar
				'sidebar'            => array(
					'font_family' => get_theme_mod( 'wpstream_theme_sidebar_font_family', '' ),
					'font_weight' => get_theme_mod( 'wpstream_theme_sidebar_font_weight', '' ),
					'font_style'  => get_theme_mod( 'wpstream_theme_sidebar_font_style', '' ),
				),
				// footer
				'footer'             => array(
					'font_family' => get_theme_mod( 'wpstream_theme_footer_font_family', '' ),
					'font_weight' => get_theme_mod( 'wpstream_theme_footer_font_weight', '' ),
					'font_style'  => get_theme_mod( 'wpstream_theme_footer_font_style', '' ),
				),
				// body
				'body'               => array(
					'font_family' => get_theme_mod( 'wpstream_typography_body_font_family', '' ),
					'font_weight' => get_theme_mod( 'wpstream_typography_body_font_weight', '' ),
					'font_style'  => get_theme_mod( 'wpstream_typography_body_font_style', '' ),
				),
				// links
				'links'              => array(
					'font_family' => get_theme_mod( 'wpstream_typography_links_font_family', '' ),
					'font_weight' => get_theme_mod( 'wpstream_typography_links_font_weight', '' ),
					'font_style'  => get_theme_mod( 'wpstream_typography_links_font_style', '' ),
				),
				// h1
				'h1'                 => array(
					'font_family' => get_theme_mod( 'wpstream_typography_headings_h1_font_family', '' ),
					'font_weight' => get_theme_mod( 'wpstream_typography_headings_h1_font_weight', '' ),
					'font_style'  => get_theme_mod( 'wpstream_typography_headings_h1_font_style', '' ),
				),
				// h2
				'h2'                 => array(
					'font_family' => get_theme_mod( 'wpstream_typography_headings_h2_font_family', '' ),
					'font_weight' => get_theme_mod( 'wpstream_typography_headings_h2_font_weight', '' ),
					'font_style'  => get_theme_mod( 'wpstream_typography_headings_h2_font_style', '' ),
				),
				// h3
				'h3'                 => array(
					'font_family' => get_theme_mod( 'wpstream_typography_headings_h3_font_family', '' ),
					'font_weight' => get_theme_mod( 'wpstream_typography_headings_h3_font_weight', '' ),
					'font_style'  => get_theme_mod( 'wpstream_typography_headings_h3_font_style', '' ),
				),
				// h4
				'h4'                 => array(
					'font_family' => get_theme_mod( 'wpstream_typography_headings_h4_font_family', '' ),
					'font_weight' => get_theme_mod( 'wpstream_typography_headings_h4_font_weight', '' ),
					'font_style'  => get_theme_mod( 'wpstream_typography_headings_h4_font_style', '' ),
				),
				// h5
				'h5'                 => array(
					'font_family' => get_theme_mod( 'wpstream_typography_headings_h5_font_family', '' ),
					'font_weight' => get_theme_mod( 'wpstream_typography_headings_h5_font_weight', '' ),
					'font_style'  => get_theme_mod( 'wpstream_typography_headings_h5_font_style', '' ),
				),
				// h6
				'h6'                 => array(
					'font_family' => get_theme_mod( 'wpstream_typography_headings_h6_font_family', '' ),
					'font_weight' => get_theme_mod( 'wpstream_typography_headings_h6_font_weight', '' ),
					'font_style'  => get_theme_mod( 'wpstream_typography_headings_h6_font_style', '' ),
				),
			);
		}

		return $font[ $type ] ?? $font;
	}
}

if ( ! function_exists( 'wpstream_generate_google_fonts' ) ) {
	/**
	 * Return google fonts url or false.
	 *
	 * @param $fonts
	 *
	 * @return false|string
	 */
	function wpstream_generate_google_fonts( $fonts ) {
		$base          = '//fonts.googleapis.com/css';
		$font_families = array();

		foreach ( $fonts as $font ) {
			if ( ! empty( $font['font_family'] ) && strpos( $font['font_family'], 'google_fonts_' ) !== false ) {
				$font['font_family'] = str_replace( 'google_fonts_', '', $font['font_family'] );
				$font_style          = $font['font_weight'] . $font['font_style'];
				$font_str            = $font['font_family'];

				if ( ! empty( $font_style ) ) {
					$font_str .= ':' . $font_style;
				}
				$font_families[] = $font_str;
			}
		}

		if ( ! empty( $font_families ) ) {
			return add_query_arg(
				array(
					'family'  => implode( '|', $font_families ),
					'display' => 'swap',
				),
				$base
			);
		} else {
			return false;
		}
	}
}

if ( ! function_exists( 'wpstream_theme_get_fonts' ) ) {
	/**
	 * Return theme fonts.
	 *
	 * @param string $type all|system|google
	 *
	 * @return string[]
	 */
	function wpstream_theme_get_fonts( $type = 'all' ) {
		$system_fonts = array(
			'-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"',
			'HelveticaNeue-Light, Helvetica Neue Light, Helvetica Neue, Helvetica, Arial, "Lucida Grande", sans-serif',
			'Arial, Helvetica, sans-serif',
			'Arial Black, Gadget, sans-serif',
			'Bookman Old Style, serif',
			'Courier, monospace',
			'Courier New, Courier, monospace',
			'Garamond, serif',
			'Georgia, serif',
			'Impact, Charcoal, sans-serif',
			'Lucida Console, Monaco, monospace',
			'Lucida Grande, Lucida Sans Unicode, sans-serif',
			'MS Sans Serif, Geneva, sans-serif',
			'MS Serif, New York, sans-serif',
			'Palatino Linotype, Book Antiqua, Palatino, serif',
			'Tahoma, Geneva, sans-serif',
			'Times New Roman, Times, serif',
			'Trebuchet MS, Helvetica, sans-serif',
			'Verdana, Geneva, sans-serif',
			'Comic Sans MS, cursive',
		);

		$google_fonts = array(
			'ABeeZee',
			'Abel',
			'Abhaya Libre',
			'Abril Fatface',
			'Aclonica',
			'Acme',
			'Actor',
			'Adamina',
			'Advent Pro',
			'Aguafina Script',
			'Akronim',
			'Aladin',
			'Alata',
			'Alatsi',
			'Aldrich',
			'Alef',
			'Alegreya',
			'Alegreya SC',
			'Alegreya Sans',
			'Alegreya Sans SC',
			'Aleo',
			'Alex Brush',
			'Alfa Slab One',
			'Alice',
			'Alike',
			'Alike Angular',
			'Allan',
			'Allerta',
			'Allerta Stencil',
			'Allura',
			'Almarai',
			'Almendra',
			'Almendra Display',
			'Almendra SC',
			'Amarante',
			'Amaranth',
			'Amatic SC',
			'Amethysta',
			'Amiko',
			'Amiri',
			'Amita',
			'Anaheim',
			'Andada',
			'Andika',
			'Angkor',
			'Annie Use Your Telescope',
			'Anonymous Pro',
			'Antic',
			'Antic Didone',
			'Antic Slab',
			'Anton',
			'Arapey',
			'Arbutus',
			'Arbutus Slab',
			'Architects Daughter',
			'Archivo',
			'Archivo Black',
			'Archivo Narrow',
			'Aref Ruqaa',
			'Arima Madurai',
			'Arimo',
			'Arizonia',
			'Armata',
			'Arsenal',
			'Artifika',
			'Arvo',
			'Arya',
			'Asap',
			'Asap Condensed',
			'Asar',
			'Asset',
			'Assistant',
			'Astloch',
			'Asul',
			'Athiti',
			'Atma',
			'Atomic Age',
			'Aubrey',
			'Audiowide',
			'Autour One',
			'Average',
			'Average Sans',
			'Averia Gruesa Libre',
			'Averia Libre',
			'Averia Sans Libre',
			'Averia Serif Libre',
			'B612',
			'B612 Mono',
			'Bad Script',
			'Bahiana',
			'Bahianita',
			'Bai Jamjuree',
			'Baloo 2',
			'Baloo Bhai 2',
			'Baloo Bhaina 2',
			'Baloo Chettan 2',
			'Baloo Da 2',
			'Baloo Paaji 2',
			'Baloo Tamma 2',
			'Baloo Tammudu 2',
			'Baloo Thambi 2',
			'Balsamiq Sans',
			'Balthazar',
			'Bangers',
			'Barlow',
			'Barlow Condensed',
			'Barlow Semi Condensed',
			'Barriecito',
			'Barrio',
			'Basic',
			'Baskervville',
			'Battambang',
			'Baumans',
			'Bayon',
			'Be Vietnam',
			'Bebas Neue',
			'Belgrano',
			'Bellefair',
			'Belleza',
			'Bellota',
			'Bellota Text',
			'BenchNine',
			'Bentham',
			'Berkshire Swash',
			'Beth Ellen',
			'Bevan',
			'Big Shoulders Display',
			'Big Shoulders Inline Display',
			'Big Shoulders Inline Text',
			'Big Shoulders Stencil Display',
			'Big Shoulders Stencil Text',
			'Big Shoulders Text',
			'Bigelow Rules',
			'Bigshot One',
			'Bilbo',
			'Bilbo Swash Caps',
			'BioRhyme',
			'BioRhyme Expanded',
			'Biryani',
			'Bitter',
			'Black And White Picture',
			'Black Han Sans',
			'Black Ops One',
			'Blinker',
			'Bokor',
			'Bonbon',
			'Boogaloo',
			'Bowlby One',
			'Bowlby One SC',
			'Brawler',
			'Bree Serif',
			'Bubblegum Sans',
			'Bubbler One',
			'Buda',
			'Buenard',
			'Bungee',
			'Bungee Hairline',
			'Bungee Inline',
			'Bungee Outline',
			'Bungee Shade',
			'Butcherman',
			'Butterfly Kids',
			'Cabin',
			'Cabin Condensed',
			'Cabin Sketch',
			'Caesar Dressing',
			'Cagliostro',
			'Cairo',
			'Caladea',
			'Calistoga',
			'Calligraffitti',
			'Cambay',
			'Cambo',
			'Candal',
			'Cantarell',
			'Cantata One',
			'Cantora One',
			'Capriola',
			'Cardo',
			'Carme',
			'Carrois Gothic',
			'Carrois Gothic SC',
			'Carter One',
			'Castoro',
			'Catamaran',
			'Caudex',
			'Caveat',
			'Caveat Brush',
			'Cedarville Cursive',
			'Ceviche One',
			'Chakra Petch',
			'Changa',
			'Changa One',
			'Chango',
			'Charm',
			'Charmonman',
			'Chathura',
			'Chau Philomene One',
			'Chela One',
			'Chelsea Market',
			'Chenla',
			'Cherry Cream Soda',
			'Cherry Swash',
			'Chewy',
			'Chicle',
			'Chilanka',
			'Chivo',
			'Chonburi',
			'Cinzel',
			'Cinzel Decorative',
			'Clicker Script',
			'Coda',
			'Coda Caption',
			'Codystar',
			'Coiny',
			'Combo',
			'Comfortaa',
			'Comic Neue',
			'Coming Soon',
			'Commissioner',
			'Concert One',
			'Condiment',
			'Content',
			'Contrail One',
			'Convergence',
			'Cookie',
			'Copse',
			'Corben',
			'Cormorant',
			'Cormorant Garamond',
			'Cormorant Infant',
			'Cormorant SC',
			'Cormorant Unicase',
			'Cormorant Upright',
			'Courgette',
			'Courier Prime',
			'Cousine',
			'Coustard',
			'Covered By Your Grace',
			'Crafty Girls',
			'Creepster',
			'Crete Round',
			'Crimson Pro',
			'Crimson Text',
			'Croissant One',
			'Crushed',
			'Cuprum',
			'Cute Font',
			'Cutive',
			'Cutive Mono',
			'DM Mono',
			'DM Sans',
			'DM Serif Display',
			'DM Serif Text',
			'Damion',
			'Dancing Script',
			'Dangrek',
			'Darker Grotesque',
			'David Libre',
			'Dawning of a New Day',
			'Days One',
			'Dekko',
			'Delius',
			'Delius Swash Caps',
			'Delius Unicase',
			'Della Respira',
			'Denk One',
			'Devonshire',
			'Dhurjati',
			'Didact Gothic',
			'Diplomata',
			'Diplomata SC',
			'Do Hyeon',
			'Dokdo',
			'Domine',
			'Donegal One',
			'Doppio One',
			'Dorsa',
			'Dosis',
			'Dr Sugiyama',
			'Duru Sans',
			'Dynalight',
			'EB Garamond',
			'Eagle Lake',
			'East Sea Dokdo',
			'Eater',
			'Economica',
			'Eczar',
			'El Messiri',
			'Electrolize',
			'Elsie',
			'Elsie Swash Caps',
			'Emblema One',
			'Emilys Candy',
			'Encode Sans',
			'Encode Sans Condensed',
			'Encode Sans Expanded',
			'Encode Sans Semi Condensed',
			'Encode Sans Semi Expanded',
			'Engagement',
			'Englebert',
			'Enriqueta',
			'Epilogue',
			'Erica One',
			'Esteban',
			'Euphoria Script',
			'Ewert',
			'Exo',
			'Exo 2',
			'Expletus Sans',
			'Fahkwang',
			'Fanwood Text',
			'Farro',
			'Farsan',
			'Fascinate',
			'Fascinate Inline',
			'Faster One',
			'Fasthand',
			'Fauna One',
			'Faustina',
			'Federant',
			'Federo',
			'Felipa',
			'Fenix',
			'Finger Paint',
			'Fira Code',
			'Fira Mono',
			'Fira Sans',
			'Fira Sans Condensed',
			'Fira Sans Extra Condensed',
			'Fjalla One',
			'Fjord One',
			'Flamenco',
			'Flavors',
			'Fondamento',
			'Fontdiner Swanky',
			'Forum',
			'Francois One',
			'Frank Ruhl Libre',
			'Freckle Face',
			'Fredericka the Great',
			'Fredoka One',
			'Freehand',
			'Fresca',
			'Frijole',
			'Fruktur',
			'Fugaz One',
			'GFS Didot',
			'GFS Neohellenic',
			'Gabriela',
			'Gaegu',
			'Gafata',
			'Galada',
			'Galdeano',
			'Galindo',
			'Gamja Flower',
			'Gayathri',
			'Gelasio',
			'Gentium Basic',
			'Gentium Book Basic',
			'Geo',
			'Geostar',
			'Geostar Fill',
			'Germania One',
			'Gidugu',
			'Gilda Display',
			'Girassol',
			'Give You Glory',
			'Glass Antiqua',
			'Glegoo',
			'Gloria Hallelujah',
			'Goblin One',
			'Gochi Hand',
			'Goldman',
			'Gorditas',
			'Gothic A1',
			'Gotu',
			'Goudy Bookletter 1911',
			'Graduate',
			'Grand Hotel',
			'Grandstander',
			'Gravitas One',
			'Great Vibes',
			'Grenze',
			'Grenze Gotisch',
			'Griffy',
			'Gruppo',
			'Gudea',
			'Gugi',
			'Gupter',
			'Gurajada',
			'Habibi',
			'Halant',
			'Hammersmith One',
			'Hanalei',
			'Hanalei Fill',
			'Handlee',
			'Hanuman',
			'Happy Monkey',
			'Harmattan',
			'Headland One',
			'Heebo',
			'Henny Penny',
			'Hepta Slab',
			'Herr Von Muellerhoff',
			'Hi Melody',
			'Hind',
			'Hind Guntur',
			'Hind Madurai',
			'Hind Siliguri',
			'Hind Vadodara',
			'Holtwood One SC',
			'Homemade Apple',
			'Homenaje',
			'IBM Plex Mono',
			'IBM Plex Sans',
			'IBM Plex Sans Condensed',
			'IBM Plex Serif',
			'IM Fell DW Pica',
			'IM Fell DW Pica SC',
			'IM Fell Double Pica',
			'IM Fell Double Pica SC',
			'IM Fell English',
			'IM Fell English SC',
			'IM Fell French Canon',
			'IM Fell French Canon SC',
			'IM Fell Great Primer',
			'IM Fell Great Primer SC',
			'Ibarra Real Nova',
			'Iceberg',
			'Iceland',
			'Imprima',
			'Inconsolata',
			'Inder',
			'Indie Flower',
			'Inika',
			'Inknut Antiqua',
			'Inria Sans',
			'Inria Serif',
			'Inter',
			'Irish Grover',
			'Istok Web',
			'Italiana',
			'Italianno',
			'Itim',
			'Jacques Francois',
			'Jacques Francois Shadow',
			'Jaldi',
			'JetBrains Mono',
			'Jim Nightshade',
			'Jockey One',
			'Jolly Lodger',
			'Jomhuria',
			'Jomolhari',
			'Josefin Sans',
			'Josefin Slab',
			'Jost',
			'Joti One',
			'Jua',
			'Judson',
			'Julee',
			'Julius Sans One',
			'Junge',
			'Jura',
			'Just Another Hand',
			'Just Me Again Down Here',
			'K2D',
			'Kadwa',
			'Kalam',
			'Kameron',
			'Kanit',
			'Kantumruy',
			'Karla',
			'Karma',
			'Katibeh',
			'Kaushan Script',
			'Kavivanar',
			'Kavoon',
			'Kdam Thmor',
			'Keania One',
			'Kelly Slab',
			'Kenia',
			'Khand',
			'Khmer',
			'Khula',
			'Kirang Haerang',
			'Kite One',
			'Knewave',
			'KoHo',
			'Kodchasan',
			'Kosugi',
			'Kosugi Maru',
			'Kotta One',
			'Koulen',
			'Kranky',
			'Kreon',
			'Kristi',
			'Krona One',
			'Krub',
			'Kufam',
			'Kulim Park',
			'Kumar One',
			'Kumar One Outline',
			'Kumbh Sans',
			'Kurale',
			'La Belle Aurore',
			'Lacquer',
			'Laila',
			'Lakki Reddy',
			'Lalezar',
			'Lancelot',
			'Lateef',
			'Lato',
			'League Script',
			'Leckerli One',
			'Ledger',
			'Lekton',
			'Lemon',
			'Lemonada',
			'Lexend Deca',
			'Lexend Exa',
			'Lexend Giga',
			'Lexend Mega',
			'Lexend Peta',
			'Lexend Tera',
			'Lexend Zetta',
			'Libre Barcode 128',
			'Libre Barcode 128 Text',
			'Libre Barcode 39',
			'Libre Barcode 39 Extended',
			'Libre Barcode 39 Extended Text',
			'Libre Barcode 39 Text',
			'Libre Barcode EAN13 Text',
			'Libre Baskerville',
			'Libre Caslon Display',
			'Libre Caslon Text',
			'Libre Franklin',
			'Life Savers',
			'Lilita One',
			'Lily Script One',
			'Limelight',
			'Linden Hill',
			'Literata',
			'Liu Jian Mao Cao',
			'Livvic',
			'Lobster',
			'Lobster Two',
			'Londrina Outline',
			'Londrina Shadow',
			'Londrina Sketch',
			'Londrina Solid',
			'Long Cang',
			'Lora',
			'Love Ya Like A Sister',
			'Loved by the King',
			'Lovers Quarrel',
			'Luckiest Guy',
			'Lusitana',
			'Lustria',
			'M PLUS 1p',
			'M PLUS Rounded 1c',
			'Ma Shan Zheng',
			'Macondo',
			'Macondo Swash Caps',
			'Mada',
			'Magra',
			'Maiden Orange',
			'Maitree',
			'Major Mono Display',
			'Mako',
			'Mali',
			'Mallanna',
			'Mandali',
			'Manjari',
			'Manrope',
			'Mansalva',
			'Manuale',
			'Marcellus',
			'Marcellus SC',
			'Marck Script',
			'Margarine',
			'Markazi Text',
			'Marko One',
			'Marmelad',
			'Martel',
			'Martel Sans',
			'Marvel',
			'Mate',
			'Mate SC',
			'Maven Pro',
			'McLaren',
			'Meddon',
			'MedievalSharp',
			'Medula One',
			'Meera Inimai',
			'Megrim',
			'Meie Script',
			'Merienda',
			'Merienda One',
			'Merriweather',
			'Merriweather Sans',
			'Metal',
			'Metal Mania',
			'Metamorphous',
			'Metrophobic',
			'Michroma',
			'Milonga',
			'Miltonian',
			'Miltonian Tattoo',
			'Mina',
			'Miniver',
			'Miriam Libre',
			'Mirza',
			'Miss Fajardose',
			'Mitr',
			'Modak',
			'Modern Antiqua',
			'Mogra',
			'Molengo',
			'Molle',
			'Monda',
			'Monofett',
			'Monoton',
			'Monsieur La Doulaise',
			'Montaga',
			'Montez',
			'Montserrat',
			'Montserrat Alternates',
			'Montserrat Subrayada',
			'Moul',
			'Moulpali',
			'Mountains of Christmas',
			'Mouse Memoirs',
			'Mr Bedfort',
			'Mr Dafoe',
			'Mr De Haviland',
			'Mrs Saint Delafield',
			'Mrs Sheppards',
			'Mukta',
			'Mukta Mahee',
			'Mukta Malar',
			'Mukta Vaani',
			'Mulish',
			'MuseoModerno',
			'Mystery Quest',
			'NTR',
			'Nanum Brush Script',
			'Nanum Gothic',
			'Nanum Gothic Coding',
			'Nanum Myeongjo',
			'Nanum Pen Script',
			'Nerko One',
			'Neucha',
			'Neuton',
			'New Rocker',
			'News Cycle',
			'Niconne',
			'Niramit',
			'Nixie One',
			'Nobile',
			'Nokora',
			'Norican',
			'Nosifer',
			'Notable',
			'Nothing You Could Do',
			'Noticia Text',
			'Noto Sans',
			'Noto Sans HK',
			'Noto Sans JP',
			'Noto Sans KR',
			'Noto Sans SC',
			'Noto Sans TC',
			'Noto Serif',
			'Noto Serif JP',
			'Noto Serif KR',
			'Noto Serif SC',
			'Noto Serif TC',
			'Nova Cut',
			'Nova Flat',
			'Nova Mono',
			'Nova Oval',
			'Nova Round',
			'Nova Script',
			'Nova Slim',
			'Nova Square',
			'Numans',
			'Nunito',
			'Nunito Sans',
			'Odibee Sans',
			'Odor Mean Chey',
			'Offside',
			'Old Standard TT',
			'Oldenburg',
			'Oleo Script',
			'Oleo Script Swash Caps',
			'Open Sans',
			'Open Sans Condensed',
			'Oranienbaum',
			'Orbitron',
			'Oregano',
			'Orienta',
			'Original Surfer',
			'Oswald',
			'Over the Rainbow',
			'Overlock',
			'Overlock SC',
			'Overpass',
			'Overpass Mono',
			'Ovo',
			'Oxanium',
			'Oxygen',
			'Oxygen Mono',
			'PT Mono',
			'PT Sans',
			'PT Sans Caption',
			'PT Sans Narrow',
			'PT Serif',
			'PT Serif Caption',
			'Pacifico',
			'Padauk',
			'Palanquin',
			'Palanquin Dark',
			'Pangolin',
			'Paprika',
			'Parisienne',
			'Passero One',
			'Passion One',
			'Pathway Gothic One',
			'Patrick Hand',
			'Patrick Hand SC',
			'Pattaya',
			'Patua One',
			'Pavanam',
			'Paytone One',
			'Peddana',
			'Peralta',
			'Permanent Marker',
			'Petit Formal Script',
			'Petrona',
			'Philosopher',
			'Piazzolla',
			'Piedra',
			'Pinyon Script',
			'Pirata One',
			'Plaster',
			'Play',
			'Playball',
			'Playfair Display',
			'Playfair Display SC',
			'Podkova',
			'Poiret One',
			'Poller One',
			'Poly',
			'Pompiere',
			'Pontano Sans',
			'Poor Story',
			'Poppins',
			'Port Lligat Sans',
			'Port Lligat Slab',
			'Pragati Narrow',
			'Prata',
			'Preahvihear',
			'Press Start 2P',
			'Pridi',
			'Princess Sofia',
			'Prociono',
			'Prompt',
			'Prosto One',
			'Proza Libre',
			'Public Sans',
			'Puritan',
			'Purple Purse',
			'Quando',
			'Quantico',
			'Quattrocento',
			'Quattrocento Sans',
			'Questrial',
			'Quicksand',
			'Quintessential',
			'Qwigley',
			'Racing Sans One',
			'Radley',
			'Rajdhani',
			'Rakkas',
			'Raleway',
			'Raleway Dots',
			'Ramabhadra',
			'Ramaraja',
			'Rambla',
			'Rammetto One',
			'Ranchers',
			'Rancho',
			'Ranga',
			'Rasa',
			'Rationale',
			'Ravi Prakash',
			'Recursive',
			'Red Hat Display',
			'Red Hat Text',
			'Red Rose',
			'Redressed',
			'Reem Kufi',
			'Reenie Beanie',
			'Revalia',
			'Rhodium Libre',
			'Ribeye',
			'Ribeye Marrow',
			'Righteous',
			'Risque',
			'Roboto',
			'Roboto Condensed',
			'Roboto Mono',
			'Roboto Slab',
			'Rochester',
			'Rock Salt',
			'Rokkitt',
			'Romanesco',
			'Ropa Sans',
			'Rosario',
			'Rosarivo',
			'Rouge Script',
			'Rowdies',
			'Rozha One',
			'Rubik',
			'Rubik Mono One',
			'Ruda',
			'Rufina',
			'Ruge Boogie',
			'Ruluko',
			'Rum Raisin',
			'Ruslan Display',
			'Russo One',
			'Ruthie',
			'Rye',
			'Sacramento',
			'Sahitya',
			'Sail',
			'Saira',
			'Saira Condensed',
			'Saira Extra Condensed',
			'Saira Semi Condensed',
			'Saira Stencil One',
			'Salsa',
			'Sanchez',
			'Sancreek',
			'Sansita',
			'Sansita Swashed',
			'Sarabun',
			'Sarala',
			'Sarina',
			'Sarpanch',
			'Satisfy',
			'Sawarabi Gothic',
			'Sawarabi Mincho',
			'Scada',
			'Scheherazade',
			'Schoolbell',
			'Scope One',
			'Seaweed Script',
			'Secular One',
			'Sedgwick Ave',
			'Sedgwick Ave Display',
			'Sen',
			'Sevillana',
			'Seymour One',
			'Shadows Into Light',
			'Shadows Into Light Two',
			'Shanti',
			'Share',
			'Share Tech',
			'Share Tech Mono',
			'Shojumaru',
			'Short Stack',
			'Shrikhand',
			'Siemreap',
			'Sigmar One',
			'Signika',
			'Signika Negative',
			'Simonetta',
			'Single Day',
			'Sintony',
			'Sirin Stencil',
			'Six Caps',
			'Skranji',
			'Slabo 13px',
			'Slabo 27px',
			'Slackey',
			'Smokum',
			'Smythe',
			'Sniglet',
			'Snippet',
			'Snowburst One',
			'Sofadi One',
			'Sofia',
			'Solway',
			'Song Myung',
			'Sonsie One',
			'Sora',
			'Sorts Mill Goudy',
			'Source Code Pro',
			'Source Sans Pro',
			'Source Serif Pro',
			'Space Grotesk',
			'Space Mono',
			'Spartan',
			'Special Elite',
			'Spectral',
			'Spectral SC',
			'Spicy Rice',
			'Spinnaker',
			'Spirax',
			'Squada One',
			'Sree Krushnadevaraya',
			'Sriracha',
			'Srisakdi',
			'Staatliches',
			'Stalemate',
			'Stalinist One',
			'Stardos Stencil',
			'Stint Ultra Condensed',
			'Stint Ultra Expanded',
			'Stoke',
			'Strait',
			'Stylish',
			'Sue Ellen Francisco',
			'Suez One',
			'Sulphur Point',
			'Sumana',
			'Sunflower',
			'Sunshiney',
			'Supermercado One',
			'Sura',
			'Suranna',
			'Suravaram',
			'Suwannaphum',
			'Swanky and Moo Moo',
			'Syncopate',
			'Syne',
			'Syne Mono',
			'Syne Tactile',
			'Tajawal',
			'Tangerine',
			'Taprom',
			'Tauri',
			'Taviraj',
			'Teko',
			'Telex',
			'Tenali Ramakrishna',
			'Tenor Sans',
			'Text Me One',
			'Texturina',
			'Thasadith',
			'The Girl Next Door',
			'Tienne',
			'Tillana',
			'Timmana',
			'Tinos',
			'Titan One',
			'Titillium Web',
			'Tomorrow',
			'Trade Winds',
			'Trirong',
			'Trispace',
			'Trocchi',
			'Trochut',
			'Trykker',
			'Tulpen One',
			'Turret Road',
			'Ubuntu',
			'Ubuntu Condensed',
			'Ubuntu Mono',
			'Ultra',
			'Uncial Antiqua',
			'Underdog',
			'Unica One',
			'UnifrakturCook',
			'UnifrakturMaguntia',
			'Unkempt',
			'Unlock',
			'Unna',
			'VT323',
			'Vampiro One',
			'Varela',
			'Varela Round',
			'Varta',
			'Vast Shadow',
			'Vesper Libre',
			'Viaoda Libre',
			'Vibes',
			'Vibur',
			'Vidaloka',
			'Viga',
			'Voces',
			'Volkhov',
			'Vollkorn',
			'Vollkorn SC',
			'Voltaire',
			'Waiting for the Sunrise',
			'Wallpoet',
			'Walter Turncoat',
			'Warnes',
			'Wellfleet',
			'Wendy One',
			'Wire One',
			'Work Sans',
			'Xanh Mono',
			'Yanone Kaffeesatz',
			'Yantramanav',
			'Yatra One',
			'Yellowtail',
			'Yeon Sung',
			'Yeseva One',
			'Yesteryear',
			'Yrsa',
			'ZCOOL KuaiLe',
			'ZCOOL QingKe HuangYou',
			'ZCOOL XiaoWei',
			'Zeyada',
			'Zhi Mang Xing',
			'Zilla Slab',
			'Zilla Slab Highlight',
		);

		if ( $type === 'system' ) {
			return $system_fonts;
		} elseif ( $type === 'google' ) {
			return $google_fonts;
		} else {
			return array_merge( $system_fonts, $google_fonts );
		}
	}
}

if ( ! function_exists( 'wpstream_theme_get_font_weight' ) ) {
	/**
	 * Return theme font weight.
	 *
	 * @return string[]
	 */
	function wpstream_theme_get_font_weight() {
		return array(
			'100' => __( 'Thin (100)', 'hello-wpstream' ),
			'200' => __( 'Extra Light (200)', 'hello-wpstream' ),
			'300' => __( 'Light (300)', 'hello-wpstream' ),
			'400' => __( 'Regular (400)', 'hello-wpstream' ),
			'500' => __( 'Medium (500)', 'hello-wpstream' ),
			'600' => __( 'Semi Bold (600)', 'hello-wpstream' ),
			'700' => __( 'Bold (700)', 'hello-wpstream' ),
			'800' => __( 'Extra Bold (800)', 'hello-wpstream' ),
			'900' => __( 'Black (900)', 'hello-wpstream' ),
		);
	}
}

if ( ! function_exists( 'wpstream_theme_get_font_style' ) ) {
	/**
	 * Return theme font style.
	 *
	 * @return string[]
	 */
	function wpstream_theme_get_font_style() {
		return array(
			'normal' => __( 'Normal', 'hello-wpstream' ),
			'italic' => __( 'Italic', 'hello-wpstream' ),
		);
	}
}

/**
 * upload icon to menu item
 */
function custom_menu_item_custom_fields( $item_id, $item, $depth, $args ) {
	$item_icon = get_post_meta( $item_id, '_menu_item_icon', true );
	?>
	<p class="description description-wide">
		<label for="edit-menu-item-icon-<?php echo esc_attr( $item_id ); ?>">
			Icon<br>
			<input type="hidden" id="edit-menu-item-icon-<?php echo esc_attr( $item_id ); ?>" class="widefat code edit-menu-item-custom" name="menu-item-icon[<?php echo esc_attr( $item_id ); ?>]" value="<?php echo esc_attr( $item_icon ); ?>"/>
			<button type="button" class="button upload-menu-icon-button" data-item-id="<?php echo esc_attr( $item_id ); ?>">Select Icon</button>
			<button type="button" class="button remove-menu-icon-button" data-item-id="<?php echo esc_attr( $item_id ); ?>">Remove Icon</button>
			<span id="icon-preview-<?php echo esc_attr( $item_id ); ?>" class="icon-preview">
												<?php
												if ( $item_icon ) :
													?>
													<img src="<?php echo esc_url( $item_icon ); ?>" style="max-width:100px; height:auto;"><?php endif; ?></span>
		</label>
	</p>
	<?php
}

add_action( 'wp_nav_menu_item_custom_fields', 'custom_menu_item_custom_fields', 10, 4 );

function wpstream_custom_nav_menu_item_update( $menu_id, $menu_item_db_id, $args ) {
	// Check if our custom icon field is set, and save the value
	if ( isset( $_POST['menu-item-icon'][ $menu_item_db_id ] ) ) {
		$icon_value = sanitize_text_field( $_POST['menu-item-icon'][ $menu_item_db_id ] );
		update_post_meta( $menu_item_db_id, '_menu_item_icon', $icon_value );
	}
}

add_action( 'wp_update_nav_menu_item', 'wpstream_custom_nav_menu_item_update', 10, 3 );

/**
 * create check if users can stream
 */

if ( ! function_exists( 'wpstream_check_if_user_can_stream' ) ) :
	function wpstream_check_if_user_can_stream() {
	$allow_users_to_stream = get_theme_mod( 'wpstream_allow_users_to_stream_setting',true);
		if ( $allow_users_to_stream ) {
			return true;
		} else {
			return false;
		}
	}
endif;

/**
 * create bootstrap dropdown
 *
 * @param array  $values
 * @param string $class
 * @param string $id
 *
 * @return string
 */

if ( ! function_exists( 'wpstream_create_custom_dropdown' ) ) {
	/**
	 * Sanitize a number field value.
	 *
	 * @param mixed $value The value to sanitize.
	 *
	 * @return string Returns the sanitized number as a string, or an empty string if the input is not a number.
	 */
	function wpstream_create_custom_dropdown( $values, $name, $class, $id, $label, $selected_value = '' ) {
		$content_values = '';
		foreach ( $values as $key => $item_value ) {
			$content_values .= '<li><button class="dropdown-item wpstream-dropdown-item" type="button" data-value="' . esc_attr( $key ) . '" >' . esc_html( $item_value ) . '</button></li>';
		}

		$return_string = '<div class="dropdown-wrapper wpstream_dropdown_select dropdown ' . esc_attr( $class ) . '">
		<button class="btn btn-secondary dropdown-toggle" type="button" id="' . esc_attr( $id ) . '_button" data-bs-toggle="dropdown" aria-expanded="false">
		' . esc_html( $label ) . '
		</button>

		<ul class="dropdown-menu" aria-labelledby="' . esc_attr( $id ) . '">
			' . trim( $content_values ) . '
		</ul>
		<input class="dropdown-value-holder" type="hidden" id="' . esc_attr( $id ) . '" name="' . esc_attr( $name ) . '" value="' . esc_attr( $selected_value ) . '">
	  	</div>';

		return $return_string;
	}
}

/**
 * Convert hex to rgba color
 *
 * @param string $color
 * @param bool   $opacity
 *
 * @return string
 */
if ( ! function_exists( 'wpstream_hex_2_rgba' ) ) {
	/**
	 * Convert hexadecimal color code to RGBA.
	 *
	 * @param string $color   The hexadecimal color code.
	 * @param mixed  $opacity The opacity value. Optional.
	 */
	function wpstream_hex_2_rgba( $color, $opacity = false ): string {
		$default = '';

		// If color in format #RRGGBB, translate to RGB.
		if ( empty( $color ) ) {
			return $default;
		}

		if ( '#' === $color[0] && 7 === strlen( $color ) ) {
			$color = substr( $color, 1 );
		}

		if ( strlen( $color ) !== 6 ) {
			return $default;
		}

		// Get value R, G, B from HEX.
		$r = hexdec( substr( $color, 0, 2 ) );
		$g = hexdec( substr( $color, 2, 2 ) );
		$b = hexdec( substr( $color, 4, 2 ) );

		// If opacity need, add.
		if ( !empty( $opacity ) ) {
			return "rgba({$r},{$g},{$b},{$opacity})";
		} else {
			return "rgb({$r},{$g},{$b})";
		}
	}
}

if ( ! function_exists( 'wpstream_sanitize_number_field' ) ) {
	/**
	 * Sanitize a number field value.
	 *
	 * @param mixed $value The value to sanitize.
	 *
	 * @return string Returns the sanitized number as a string, or an empty string if the input is not a number.
	 */
	function wpstream_sanitize_number_field( $value ) {
		if ( is_object( $value ) || is_array( $value ) ) {
			return '';
		}

		return preg_replace( '/[^.0-9]/', '', $value );
	}
}


/**
 * Register custom endpoints for WPStream theme.
 */

function wpstream_theme_my_custom_endpoints() {
	// Add the "start-streaming" endpoint.
	add_rewrite_endpoint( 'start-streaming', EP_ROOT | EP_PAGES );

	// Add the "watch-later" endpoint.
	add_rewrite_endpoint( 'watch-later', EP_ROOT | EP_PAGES );
}
add_action( 'init', 'wpstream_theme_my_custom_endpoints' );

/*
 * Flush rewrite rules on theme activation and deactivation.
 * Removed from the wpstream_theme_my_custom_endpoints because it's expensive on every page load.
 */
function wpstream_flush_rewrite_rules_on_theme_activation() {
    // Flush rewrite rules to ensure custom endpoints are registered.
    flush_rewrite_rules();
}
add_action( 'after_switch_theme', 'wpstream_flush_rewrite_rules_on_theme_activation' );

/*
 * Flush rewrite rules on theme deactivation.
 */
function wpstream_flush_rewrite_rules_on_theme_deactivation() {
    // Flush rewrite rules to remove custom endpoints.
    flush_rewrite_rules();
}
add_action( 'switch_theme', 'wpstream_flush_rewrite_rules_on_theme_deactivation' );


/**
 * Add custom query variables for WPStream theme.
 *
 * @param array $vars An array of recognized query variable names.
 * @return array Modified array of recognized query variable names.
 */

function wpstream_my_custom_query_vars( $vars ) {
	// Add the "start-streaming" query variable.
	$vars[] = 'start-streaming';

	// Add the "watch-later" query variable.
	$vars[] = 'watch-later';

	$vars[] = 'item_post_type';
	return $vars;
}
add_filter( 'query_vars', 'wpstream_my_custom_query_vars' );




/**
 * Custom endpoint content for 'start-streaming'.
 */
function wpstream_custom_endpoint_content_start_streaming() {
	if ( class_exists( 'WpStream_Player' ) ) {
		require WPSTREAM_PLUGIN_PATH . 'hello-wpstream/template-parts/dashboard-templates/template-start-streaming.php';
	}
}

add_action( 'woocommerce_account_start-streaming_endpoint', 'wpstream_custom_endpoint_content_start_streaming' );


/**
 * Custom endpoint content for 'watch-later'.
 */
function wpstream_custom_endpoint_content_watch_later() {
	if ( class_exists( 'Wpstream_Player' ) ) {
		require WPSTREAM_PLUGIN_PATH . 'hello-wpstream/template-parts/dashboard-templates/template-watch-later.php';
	}
}
add_action( 'woocommerce_account_watch-later_endpoint', 'wpstream_custom_endpoint_content_watch_later' );


/**
 * Customizes the items in the My Account menu.
 *
 * @param array $items The original items in the My Account menu.
 * @return array The modified items in the My Account menu.
 */

/**
 * Remove woocommerce menu from woocommerce_my_account output
 */
function wpstream_my_account_content_shortcode() {
	ob_start();
	$content = '';
	echo do_shortcode( '[woocommerce_my_account]' );
	$html_content = ob_get_contents();
	ob_end_clean();

	// Remove the menu from the content.
	$dom = new DOMDocument('1.0', 'UTF-8');
	libxml_use_internal_errors( true );
	$dom->loadHTML( '<?xml encoding="UTF-8">' . $html_content );
	libxml_clear_errors();

	$xpath    = new DOMXPath( $dom );
	$elements = $xpath->query( '//div[contains(@class, "woocommerce-MyAccount-content")]' );
	if ( $elements->length > 0 ) {
		$content = $dom->saveHTML( $elements->item( 0 ) );
		echo trim( $content ); //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
	}

	return $content;
}

add_action( 'wpstream_vod_title_overlay', 'hello_wpstream_render_vod_title_overlay', 10, 3 );

function hello_wpstream_render_vod_title_overlay( $overlay_id, $title_text, $label_text ) {
	echo '<div id="' . esc_attr( $overlay_id ) . '" class="vjs-title-overlay wpstream-video-title-overlay">'
	     . esc_html( $label_text ) . ' ' . esc_html( $title_text ) .
	     '</div>';
}