<?php
/**
 * Skins support: Main skin file for the skin 'Default'
 *
 * Load scripts and styles,
 * and other operations that affect the appearance and behavior of the theme
 * when the skin is activated
 *
 * @package TOURIMO
 * @since TOURIMO 1.0.46
 */


// SKIN SETUP
//--------------------------------------------------------------------

// Setup fonts, colors, blog and single styles, etc.
$tourimo_skin_path = tourimo_get_file_dir( tourimo_skins_get_current_skin_dir() . 'skin-setup.php' );
if ( ! empty( $tourimo_skin_path ) ) {
	require_once $tourimo_skin_path;
}

// Skin options
$tourimo_skin_path = tourimo_get_file_dir( tourimo_skins_get_current_skin_dir() . 'skin-options.php' );
if ( ! empty( $tourimo_skin_path ) ) {
	require_once $tourimo_skin_path;
}

// Required plugins
$tourimo_skin_path = tourimo_get_file_dir( tourimo_skins_get_current_skin_dir() . 'skin-plugins.php' );
if ( ! empty( $tourimo_skin_path ) ) {
	require_once $tourimo_skin_path;
}

// Demo import
$tourimo_skin_path = tourimo_get_file_dir( tourimo_skins_get_current_skin_dir() . 'skin-demo-importer.php' );
if ( ! empty( $tourimo_skin_path ) ) {
	require_once $tourimo_skin_path;
}


// TRX_ADDONS SETUP
//--------------------------------------------------------------------

// Filter to add in the required plugins list
// Priority 11 to add new plugins to the end of the list
if ( ! function_exists( 'tourimo_skin_tgmpa_required_plugins' ) ) {
	add_filter( 'tourimo_filter_tgmpa_required_plugins', 'tourimo_skin_tgmpa_required_plugins', 11 );
	function tourimo_skin_tgmpa_required_plugins( $list = array() ) {
		// ToDo: Check if plugin is in the 'required_plugins' and add his parameters to the TGMPA-list
		//       Replace 'skin-specific-plugin-slug' to the real slug of the plugin
		if ( tourimo_storage_isset( 'required_plugins', 'skin-specific-plugin-slug' ) ) {
			$list[] = array(
				'name'     => tourimo_storage_get_array( 'required_plugins', 'skin-specific-plugin-slug', 'title' ),
				'slug'     => 'skin-specific-plugin-slug',
				'required' => false,
			);
		}
		foreach ($list as $key => $value) {
			if ( in_array($list[$key]['slug'], array('coblocks', 'kadence-blocks', 'booked-calendar-feeds', 'booked-frontend-agents', 'booked-woocommerce-payments', 'contact-form-7-datepicker')) ) {
				unset($list[$key]);
			}
		}
		return $list;
	}
}

// Filter to add/remove components of ThemeREX Addons when current skin is active
if ( ! function_exists( 'tourimo_skin_trx_addons_default_components' ) ) {
	add_filter('trx_addons_filter_load_options', 'tourimo_skin_trx_addons_default_components', 20);
	function tourimo_skin_trx_addons_default_components($components) {
		// ToDo: Set key value in the array $components to 0 (disable component) or 1 (enable component)
		//---> For example (enable reviews for posts):
		//---> $components['components_components_reviews'] = 1;
		return $components;
	}
}

// Filter to add/remove CPT
if ( ! function_exists( 'tourimo_skin_trx_addons_cpt_list' ) ) {
	add_filter('trx_addons_cpt_list', 'tourimo_skin_trx_addons_cpt_list');
	function tourimo_skin_trx_addons_cpt_list( $list = array() ) {
		// ToDo: Unset CPT slug from list to disable CPT when current skin is active
		//---> For example to disable CPT 'Portfolio':
		//---> unset( $list['portfolio'] );
		return $list;
	}
}

// Filter to add/remove shortcodes
if ( ! function_exists( 'tourimo_skin_trx_addons_sc_list' ) ) {
	add_filter('trx_addons_sc_list', 'tourimo_skin_trx_addons_sc_list');
	function tourimo_skin_trx_addons_sc_list( $list = array() ) {
		// ToDo: Unset shortcode's slug from list to disable shortcode when current skin is active
		//---> For example to disable shortcode 'Action':
		//---> unset( $list['action'] );

		// Also can be used to add/remove/modify shortcodes params
		//---> For example to add new template to the 'Blogger':
		//---> $list['blogger']['templates']['default']['new_template_slug'] = array(
		//--->		'title' => __('Title of the new template', 'tourimo'),
		//--->		'layout' => array(
		//--->			'featured' => array(),
		//--->			'content' => array('meta_categories', 'title', 'excerpt', 'meta', 'readmore')
		//--->		)
		//---> );

		unset($list['blogger']['templates']['default']['over_centered']);
		unset($list['blogger']['templates']['default']['over_bottom']);
		
		return $list;
	}
}

// Filter to add/remove widgets
if ( ! function_exists( 'tourimo_skin_trx_addons_widgets_list' ) ) {
	add_filter('trx_addons_widgets_list', 'tourimo_skin_trx_addons_widgets_list');
	function tourimo_skin_trx_addons_widgets_list( $list = array() ) {
		// ToDo: Unset widget's slug from list to disable widget when current skin is active
		//---> For example to disable widget 'About Me':
		//---> unset( $list['aboutme'] );
		return $list;
	}
}



// SCRIPTS AND STYLES
//--------------------------------------------------

// Enqueue skin-specific scripts
// Priority 1050 -  before main theme plugins-specific (1100)
if ( ! function_exists( 'tourimo_skin_frontend_scripts' ) ) {
	add_action( 'wp_enqueue_scripts', 'tourimo_skin_frontend_scripts', 1050 );
	function tourimo_skin_frontend_scripts() {
		$tourimo_url = tourimo_get_file_url( tourimo_skins_get_current_skin_dir() . 'css/style.css' );
		if ( '' != $tourimo_url ) {
			wp_enqueue_style( 'tourimo-skin-' . esc_attr( tourimo_skins_get_current_skin_name() ), $tourimo_url, array(), null );
		}
		$tourimo_url = tourimo_get_file_url( tourimo_skins_get_current_skin_dir() . 'skin.js' );
		if ( '' != $tourimo_url ) {
			wp_enqueue_script( 'tourimo-skin-' . esc_attr( tourimo_skins_get_current_skin_name() ), $tourimo_url, array( 'jquery' ), null, true );
		}
	}
}


// Custom styles
$tourimo_style_path = tourimo_get_file_dir( tourimo_skins_get_current_skin_dir() . 'css/style.php' );
if ( ! empty( $tourimo_style_path ) ) {
	require_once $tourimo_style_path;
}



//--------------------------------------------------
// NEW FUNCTIONS
//--------------------------------------------------
// Theme init priorities:
/// add/remove Theme Options elements
if ( ! function_exists( 'tourimo_skin_theme_setup4' ) ) {
	add_action( 'after_setup_theme', 'tourimo_skin_theme_setup4', 4 );
	function tourimo_skin_theme_setup4() {
		if ( tourimo_exists_team() ) {
			tourimo_storage_set_array_after(
				'options', 'single_info_team', 'header_type_single_team', array(
						'title'    => esc_html__( 'Header style', 'tourimo' ),
						'desc'     => wp_kses_data( __( 'Choose whether to use the default header or header Layouts (available only if the ThemeREX Addons is activated)', 'tourimo' ) ),
						'std'      => 'inherit',
						'options'  => tourimo_get_list_header_footer_types( true ), 
						'type'     => TOURIMO_THEME_FREE ? 'hidden' : 'radio',					
				)
			);

			tourimo_storage_set_array_after(
				'options', 'header_type_single_team', 'header_style_single_team', array(
						'title'      => esc_html__( 'Select custom layout', 'tourimo' ),
						'desc'       => wp_kses( __( 'Select custom header from Layouts Builder', 'tourimo' ), 'tourimo_kses_content' ),
						'dependency' => array(
							'header_type_single_team' => array( 'custom' ),
						),
						'std'        => 'inherit',
						'options'    => array(),
						'type'       => TOURIMO_THEME_FREE ? 'hidden' : 'select',					
				)
			);
		}
		// Remove Booked plugins installation
		remove_action( 'bookedpa_register', 'booked_register_required_plugins' );
	}
}

// Theme init priorities:
//10 - standard Theme init procedures (not ordered)
if ( ! function_exists( 'tourimo_skin_theme_setup10' ) ) {
	add_action( 'after_setup_theme', 'tourimo_skin_theme_setup10', 10 );
	function tourimo_skin_theme_setup10() {
		// Related posts
		$related_position = tourimo_get_theme_option( 'related_position' );
		$posts_navigation = tourimo_get_theme_option( 'posts_navigation' );
		$full_post_loading = tourimo_get_value_gp( 'action' ) == 'full_post_loading';
		if ( 'below_content' == $related_position
			&& ( 'scroll' != $posts_navigation || tourimo_get_theme_option( 'posts_navigation_scroll_hide_related' ) == 0 )
			&& ( ! $full_post_loading || tourimo_get_theme_option( 'open_full_post_hide_related' ) == 0 )
		) {
			remove_action( 'tourimo_action_related_posts', 'tourimo_show_related_posts_callback' );
		}
		
		if ( tourimo_exists_woocommerce() ) {
			remove_action( 'woocommerce_before_shop_loop_item_title', 'tourimo_woocommerce_title_tags', 30 );
		}
	}
}

// Remove TRX Addons options
if ( ! function_exists( 'tourimo_skin_trx_addons_options' ) ) {
	add_filter( 'trx_addons_filter_options', 'tourimo_skin_trx_addons_options', 1100 );
	function tourimo_skin_trx_addons_options( $list = array() ) {
		if ( true ) {
			$list['banners_section']['type'] = 
			$list['emotions_info']['type'] = 
			$list['emotions_allowed']['type'] =	
			$list['posts_banners']['type'] = 'hidden';

			$list['posts_banners']['std'] =
			$list['posts_banners']['val'] =
			$list['banners_section']['std'] = 
			$list['emotions_info']['std'] = '';
		}
		return $list;
	}
}

// Show related posts before comments
if ( ! function_exists( 'tourimo_skin_show_related_posts' ) ) {
	add_action( 'tourimo_action_after_post_footer', 'tourimo_skin_show_related_posts' );
	function tourimo_skin_show_related_posts() {
		// Related posts
		$related_position = tourimo_get_theme_option( 'related_position' );
		$posts_navigation = tourimo_get_theme_option( 'posts_navigation' );
		$full_post_loading = tourimo_get_value_gp( 'action' ) == 'full_post_loading';
		if ( 'below_content' == $related_position
			&& ( 'scroll' != $posts_navigation || tourimo_get_theme_option( 'posts_navigation_scroll_hide_related' ) == 0 )
			&& ( ! $full_post_loading || tourimo_get_theme_option( 'open_full_post_hide_related' ) == 0 )
		) {
			tourimo_show_related_posts_callback();
		}
	}
}

// Get next post terms list
if ( ! function_exists( 'tourimo_skin_next_post_terms_list' ) ) {
	function tourimo_skin_next_post_terms_list() {
		$tourimo_next_post_cat_list = '';
		$tourimo_next_post = get_next_post();
		if ( !empty( $tourimo_next_post ) ) {
			$tourimo_next_post_cat_list = get_the_category_list( '. ', '', $tourimo_next_post->ID );
		}
		return $tourimo_next_post_cat_list;
	}
}

// Get prev post terms list
if ( ! function_exists( 'tourimo_skin_prev_post_terms_list' ) ) {
	function tourimo_skin_prev_post_terms_list() {
		$tourimo_prev_post_cat_list = '';
		$tourimo_prev_post = get_previous_post();
		if ( !empty( $tourimo_prev_post ) ) {
			$tourimo_prev_post_cat_list = get_the_category_list( '. ', '', $tourimo_prev_post->ID );
		}
		return $tourimo_prev_post_cat_list;
	}
}

// Return list with image's hovers
if ( ! function_exists( 'tourimo_skin_list_hovers' ) ) {
	add_filter( 'tourimo_filter_list_hovers', 'tourimo_skin_list_hovers' );
	function tourimo_skin_list_hovers($list) {
		$list = array(
				'icon'    		=> esc_html__( 'Icon', 'tourimo' ),
				'shop_buttons'  => esc_html__( 'Buttons', 'tourimo' )
			);
		return $list;
	}
}

// Add theme-specific controls to sections and columns
if ( ! function_exists( 'tourimo_skin_elm_add_controls' ) ) {
	add_action( 'elementor/element/before_section_end', 'tourimo_skin_elm_add_controls', 10, 3 );
	function tourimo_skin_elm_add_controls( $element, $section_id, $args ) {
		if ( is_object( $element ) ) {
			$el_name = $element->get_name();
			// Shortcode: Socials
			if ( in_array($el_name, array('trx_sc_socials')) && !$element->get_controls('position') ) { 
				$element->add_control(  
					'position', array(
						'label' 		=> __("Icons position", 'tourimo'),
						'type'		=> \Elementor\Controls_Manager::SELECT,
						'options' 	=> array(
							'horizontal'	=> __("Horizontal", 'tourimo'),
							'vertical'		=> __("Vertical", 'tourimo')
						),
						'default' 	=> 'horizontal'
					)
				);
			}
		}
	}
}

// add wrap to slider img
	if ( ! function_exists( 'tourimo_skin_trx_addons_filter_slider_image' ) ) {
	add_filter( 'trx_addons_filter_slider_image', 'tourimo_skin_trx_addons_filter_slider_image', 10, 1 );
	function tourimo_skin_trx_addons_filter_slider_image( $content ) {
	$newcontent = '<div class="slide_img_wrap">'. $content .'</div>';
	return $newcontent;
		}
	}

// add wrap to slider img
	if ( ! function_exists( 'tourimo_skin_trx_addons_filter_slider_image' ) ) {
	add_filter( 'trx_addons_filter_slider_image', 'tourimo_skin_trx_addons_filter_slider_image', 10, 1 );
	function tourimo_skin_trx_addons_filter_slider_image( $content ) {
	$newcontent = '<div class="slide_img_wrap">'. $content .'</div>';
	return $newcontent;
		}
	}

// Add theme-specific controls to shortcodes
if ( ! function_exists( 'tourimo_skin_trx_addons_sc_param_group_params' ) ) {
	add_filter( 'trx_addons_sc_param_group_params', 'tourimo_skin_trx_addons_sc_param_group_params', 10, 2 );
	function tourimo_skin_trx_addons_sc_param_group_params( $array, $sc ) {
		// Shortcode: Action
		if ( $sc == 'trx_sc_action' ) {
			$array[0]['condition'] = 
			$array[2]['condition'] = 
			$array[3]['condition'] = 
			$array[4]['condition'] = 
			$array[5]['condition'] = 
			$array[8]['condition'] = 
			$array[9]['condition'] = 
			$array[10]['condition'] = array( 'type' => ['default']);
		}
		return $array;
	}
}

// Add theme-specific controls to shortcodes
if ( ! function_exists( 'tourimo_skin_trx_addons_sc_param_group_value' ) ) {
	add_filter( 'trx_addons_sc_param_group_value', 'tourimo_skin_trx_addons_sc_param_group_value', 10, 2 );
	function tourimo_skin_trx_addons_sc_param_group_value( $array, $sc ) {
		// Shortcode: Action
		if ( $sc == 'trx_sc_action' ) {
			$arr = array();
			$arr[] = array(
							'title' => esc_html__( 'First action', 'tourimo' ),
							'link' => ['url' => '#'],
							'link_text' => esc_html__( 'Read More', 'tourimo' ),
						);
			$array = $arr;
		}
		return $array;
	}
}

// Return list of the slider titles
if ( ! function_exists( 'tourimo_skin_trx_addons_get_list_sc_slider_titles' ) ) {
	add_filter( 'trx_addons_filter_get_list_sc_slider_titles', 'tourimo_skin_trx_addons_get_list_sc_slider_titles' );
	function tourimo_skin_trx_addons_get_list_sc_slider_titles( $array ) {
		$array = array(
			'no' => esc_html__('No titles', 'tourimo'),
			'center' => esc_html__('Center', 'tourimo'),
			'lt' => esc_html__('Top Left', 'tourimo'),
		);
		return $array;
	}
}

// Return meta value
if ( ! function_exists( 'tourimo_skin_trx_addons_custom_meta_value' ) ) {
	add_filter( 'trx_addons_filter_custom_meta_value', 'tourimo_skin_trx_addons_custom_meta_value' );
	function tourimo_skin_trx_addons_custom_meta_value( $price ) {
		if ( strpos($price,'person') !== false ) {
			$price = str_replace('/person', '<span class="person">/person</span>', $price);
		}
		if ( strpos($price,'from') !== false ) {
			$price = str_replace('from ', '<span class="from">from </span>', $price);
		}
		return $price;
	}
}

// Add new params to the widget's atts
if ( ! function_exists( 'tourimo_skin_trx_addons_widget_args' ) ) {
	add_filter( 'trx_addons_filter_widget_args', 'tourimo_skin_trx_addons_widget_args', 10, 3 );
	function tourimo_skin_trx_addons_widget_args( $atts, $instance, $sc ) {
		// Slider
		if ( 'trx_addons_widget_slider' == $sc ) {
			$atts['slides_min_width'] = 200;
		}	
		return $atts;
	}
}

// Return theme-specific post meta args
if ( ! function_exists( 'tourimo_skin_post_meta_args' ) ) {
	add_filter( 'tourimo_filter_post_meta_args', 'tourimo_skin_post_meta_args', 100, 3 );
	function tourimo_skin_post_meta_args( $args = array(), $from = '', $columns = 1 ) {
		if ( $from == 'single' && $columns == 1 ) {
			if ( $args['class'] == 'post_meta_categories' ) {
				$args['components'] = '';				
			}
			if ( $args['class'] == 'post_meta_other_part1' ) {
				$meta_components = tourimo_get_theme_option( 'meta_parts' );
				if ( ! is_array( $meta_components ) ) {
					parse_str( str_replace( '|', '&', $meta_components ), $meta_components );
				}
				$components = array_keys( tourimo_array_slice( $meta_components, '', $args['split_meta_by'] ), 1 );
				$args['components'] = join( ',', $components );				  
			}
		}	
		return $args; 
	}
}

// TRX Addons list input hovers
if ( ! function_exists( 'tourimo_skin_trx_addons_get_list_input_hover' ) ) {
	add_filter( 'trx_addons_filter_get_list_input_hover', 'tourimo_skin_trx_addons_get_list_input_hover' );
	function tourimo_skin_trx_addons_get_list_input_hover( $list = array() ) {
		$list = array(
			'default'	=> esc_html__('Default',	'tourimo'),
			'underline'	=> esc_html__('Underline',	'tourimo'),
		);
		return $list;
	}
}

// Button colors
if ( ! function_exists( 'tourimo_skin_list_sc_color_styles' ) ) {
	add_filter( 'tourimo_filter_get_list_sc_color_styles', 'tourimo_skin_list_sc_color_styles' );
	function tourimo_skin_list_sc_color_styles( $list = array() ) {
		$list = array(
				'default' => esc_html__( 'Default', 'tourimo' ),
				'link2'   => esc_html__( 'Dark', 'tourimo' ),
				'alter'   => esc_html__( 'Alter', 'tourimo' ),
			);
		return $list;
	}
}

// Sidebar posisiton
if ( ! function_exists( 'tourimo_skin_list_sidebars_positions_ss' ) ) {
	add_filter( 'tourimo_filter_list_sidebars_positions_ss', 'tourimo_skin_list_sidebars_positions_ss' );
	function tourimo_skin_list_sidebars_positions_ss( $list = array() ) {
		$list = array(
				'below' => esc_html__( 'Below the content', 'tourimo' ),
			);
		return $list;
	}
}

// Return 'expand content' choices
if ( ! function_exists( 'tourimo_skin_list_expand_content' ) ) {
	add_filter( 'tourimo_filter_list_expand_content', 'tourimo_skin_list_expand_content' );
	function tourimo_skin_list_expand_content( $list = array() ) {
		$list = array(
				'normal' => array(
							'title' => esc_html__( 'Normal', 'tourimo' ),
							'icon'  => 'images/theme-options/expand-content/normal.png',
						),
				'expand' => array(
							'title' => esc_html__( 'Wide', 'tourimo' ),
							'icon'  => 'images/theme-options/expand-content/wide.png',
						),
			);
		return $list;
	}
}

// Return share links positions
if ( ! function_exists( 'tourimo_skin_list_share_links_positions' ) ) {
	add_filter( 'tourimo_filter_list_share_links_positions', 'tourimo_skin_list_share_links_positions' );
	function tourimo_skin_list_share_links_positions( $list = array() ) {
		$list = array(
				'bottom' => esc_html__( 'Bottom', 'tourimo' ),
			);
		return $list;
	}
}

// Add accent colors to the 'Quick Setup' section in the Theme Panel
if ( ! function_exists( 'tourimo_skin_options_qsetup_add_accent_colors' ) ) {
	add_filter( 'tourimo_filter_qsetup_options', 'tourimo_skin_options_qsetup_add_accent_colors', 11 );
	function tourimo_skin_options_qsetup_add_accent_colors( $list = array() ) {		
		unset($list['colors_text_link3']);
		unset($list['colors_text_hover3']);
		return $list;
	}
}

// Return theme specific widgetized areas
if ( ! function_exists( 'tourimo_skin_list_sidebars' ) ) {
	add_filter('tourimo_filter_list_sidebars', 'tourimo_skin_list_sidebars');
	function tourimo_skin_list_sidebars( $list = array() ) {
		unset($list['header_widgets']);
		unset($list['above_page_widgets']);
		unset($list['above_content_widgets']);
		unset($list['below_content_widgets']);
		unset($list['below_page_widgets']);
		return $list;
	}
}

// Fill 'options' arrays when its need in the admin mode
if ( ! function_exists( 'tourimo_skin_trx_addons_page_contact_form' ) ) {
	add_filter('trx_addons_filter_page_contact_form', 'tourimo_skin_trx_addons_page_contact_form', 11, 2 );
	function tourimo_skin_trx_addons_page_contact_form( $list = array(), $cpt ) {	
		if ( $cpt == 'services' ) {
			unset($list['default']);
		}
		if ( $cpt == 'team' ) {
			unset($list['default']);
		} 
		return $list;
	}
}

// Enqueue skin-specific scripts
// Priority 1050 -  before main theme plugins-specific (1100)
if ( ! function_exists( 'tourimo_skin_frontend_scripts2' ) ) {
	add_action( 'wp_enqueue_scripts', 'tourimo_skin_frontend_scripts2', 1210 );
	function tourimo_skin_frontend_scripts2() {	
		$tourimo_url = tourimo_get_file_url( tourimo_skins_get_current_skin_dir() . 'css/skin-responsive.css' );
		if ( '' != $tourimo_url ) {
			wp_enqueue_style( 'tourimo-skin-responsive-' . esc_attr( tourimo_skins_get_current_skin_name() ), $tourimo_url, array(), null );
		}
	}
}

// Team posts title
if ( ! function_exists( 'tourimo_skin_team_posts_title' ) ) {
	add_filter( 'trx_addons_filter_team_posts_title', 'tourimo_skin_team_posts_title' );
	function tourimo_skin_team_posts_title() {	
		return __('Drop a line', 'tourimo');
	}
}


// Return array with current system info
if ( ! function_exists( 'tourimo_skin_trx_addons_get_sys_info' ) ) {
	add_filter( 'trx_addons_filter_get_sys_info', 'tourimo_skin_trx_addons_get_sys_info' );
	function tourimo_skin_trx_addons_get_sys_info($array) {	
		$array['php_version']['recommended'] = '7.0.0+';
		$array['wp_version']['recommended'] = '5.0.0+';
		return $array;
	}
}

// Add custom animations
if ( ! function_exists( 'tourimo_skin_elm_add_theme_animations' ) ) {
	add_filter( 'elementor/controls/animations/additional_animations', 'tourimo_skin_elm_add_theme_animations' );
	function tourimo_skin_elm_add_theme_animations( $animations ) {
		return array_merge( $animations, array(
			esc_html__( 'Theme Specific', 'tourimo' ) => array(
				'tourimo-fadeinup' => esc_html__( 'Tourimo - Fade In Up', 'tourimo' ),
				'tourimo-fadeinright' => esc_html__( 'Tourimo - Fade In Right', 'tourimo' ),
				'tourimo-fadeinleft' => esc_html__( 'Tourimo - Fade In Left', 'tourimo' ),
				'tourimo-fadeindown' => esc_html__( 'Tourimo - Fade In Down', 'tourimo' ),
				'tourimo-fadein' => esc_html__( 'Tourimo - Fade In', 'tourimo' ),
				'tourimo-blur' => esc_html__( 'Tourimo - Blur', 'tourimo' )
			)
		) );
	}
}

//--------------------------------------------------
// Rewrited functions
//--------------------------------------------------
// Return image of current post/page/category/blog mode
if ( ! function_exists( 'tourimo_skin_get_current_mode_image' ) ) {
	function tourimo_skin_get_current_mode_image( $default = '' ) {
		if ( is_category() ) {
			$img = tourimo_get_term_image();
			if ( '' != $img ) {
				$default = $img;
			}
		} elseif ( is_singular() || tourimo_storage_isset( 'blog_archive' ) ) {
			if ( has_post_thumbnail() ) {
				$img = wp_get_attachment_image_src( get_post_thumbnail_id(), 'full' );
				if ( is_array( $img ) ) {
					$default = $img[0];
				}
			}
		}
		return $default;
	}
}

// Show single post footer: tags, likes and share
if ( ! function_exists( 'tourimo_show_post_footer' ) ) {
	function tourimo_show_post_footer( $components = 'pages,tags,likes,share,prev_next,author' ) {
		$components               = array_map( 'trim', explode( ',', $components ) );
		$meta_components          = tourimo_array_get_keys_by_value( tourimo_get_theme_option( 'meta_parts' ) );
		$share_position           = tourimo_array_get_keys_by_value( tourimo_get_theme_option( 'share_position' ) );
		$full_post_loading        = tourimo_get_value_gp( 'action' ) == 'full_post_loading';
		$tourimo_posts_navigation = tourimo_get_theme_option( 'posts_navigation' );

		foreach( $components as $comp ) {

			if ( 'tags' == $comp ) {

				// Post tags
				the_tags( '<div class="post_tags_single"><span class="post_meta_label">' . esc_html__( 'Tags:', 'tourimo' ) . '</span> ', ',', '</div>' );

			} else if ( 'likes' == $comp ) {

				// Emotions
				if ( tourimo_exists_trx_addons() && function_exists( 'trx_addons_get_post_reactions' ) && trx_addons_is_on( trx_addons_get_option( 'emotions_allowed' ) ) ) {
					trx_addons_get_post_reactions( true );
				}

			} else if ( 'share' == $comp ) {

				//  Share
				$meta_footer = array();
				if ( false &&  in_array( 'likes', $components ) && in_array( 'likes', $meta_components )
						&&
						( ! function_exists( 'trx_addons_get_option' ) || trx_addons_is_off( trx_addons_get_option( 'emotions_allowed' ) ) || ! apply_filters( 'trx_addons_filter_show_post_reactions', is_single() && ! is_attachment() ) )
				) {
					$meta_footer[] = 'likes';
				}
				if ( in_array( 'bottom', $share_position ) ) {
					$meta_footer[] = 'share';
				}
				if ( count( $meta_footer) > 0 ) {
					ob_start();
					tourimo_show_post_meta(
						apply_filters(
							'tourimo_filter_post_meta_args',
							array(
								'components' => join( ',', $meta_footer ),
								'class'      => 'post_meta_single',
								'share_type' => 'block',
								'caption'   => esc_html__( 'Share:', 'tourimo' ),
							),
							'single',
							1
						)
					);
					$tourimo_meta_output = ob_get_contents();
					ob_end_clean();
					if ( ! empty( $tourimo_meta_output ) ) {
						do_action( 'tourimo_action_before_post_meta' );
						tourimo_show_layout( $tourimo_meta_output );
						do_action( 'tourimo_action_after_post_meta' );
					}
				}

			} else if ( 'author' == $comp ) {

				// Author bio
				if ( tourimo_get_theme_option( 'show_author_info' ) == 1
					&& ! is_attachment()
					&& get_the_author_meta( 'description' )
					&& ( 'scroll' != $tourimo_posts_navigation || tourimo_get_theme_option( 'posts_navigation_scroll_hide_author' ) == 0 )
					&& ( ! $full_post_loading || tourimo_get_theme_option( 'open_full_post_hide_author' ) == 0 )
				) {
					do_action( 'tourimo_action_before_post_author' );
					get_template_part( apply_filters( 'tourimo_filter_get_template_part', 'templates/author-bio' ) );
					do_action( 'tourimo_action_after_post_author' );
				}

			} else if ( 'prev_next' == $comp ) {

				// Previous/next post navigation.
				if ( 'links' == $tourimo_posts_navigation && ! $full_post_loading ) {
					do_action( 'tourimo_action_before_post_navigation' );
					?>
					<div class="nav-links-single<?php
						if ( tourimo_get_theme_setting( 'thumbs_in_navigation' ) ) {
							echo ' nav-links-with-thumbs';
						}
						if ( ! tourimo_is_off( tourimo_get_theme_option( 'posts_navigation_fixed' ) ) ) {
							echo ' nav-links-fixed fixed';
						}
					?>">
						<?php
						the_post_navigation(
							array(
								'next_text' => '<span class="nav-arrow"></span>'
									. '<span class="screen-reader-text">' . esc_html__( 'Next Post', 'tourimo' ) . '</span> '
									. '<div class="post_meta_item post_categories">'. tourimo_skin_next_post_terms_list() . '</div>'
									. '<h6 class="post-title">%title</h6>'
									. '<span class="post_date">%date</span>',
								'prev_text' => '<span class="nav-arrow"></span>'
									. '<span class="screen-reader-text">' . esc_html__( 'Previous Post', 'tourimo' ) . '</span> '
									. '<div class="post_meta_item post_categories">'. tourimo_skin_prev_post_terms_list() . '</div>'
									. '<h6 class="post-title">%title</h6>'
									. '<span class="post_date">%date</span>',
							)
						);
						?>
					</div>
					<?php
					do_action( 'tourimo_action_after_post_navigation' );
				}

			}
		}
	}
}