<?php

// Check if shortcodes settings are now used
if ( !function_exists( 'seohub_shortcodes_is_used' ) ) {
	function seohub_shortcodes_is_used() {
		return seohub_options_is_used() 															// All modes when Theme Options are used
			|| (is_admin() && isset($_POST['action']) 
					&& in_array($_POST['action'], array('vc_edit_form', 'wpb_show_edit_form')))		// AJAX query when save post/page
			|| (function_exists('seohub_vc_is_frontend') && seohub_vc_is_frontend());		// VC Frontend editor mode
	}
}

// Width and height params
if ( !function_exists( 'seohub_shortcodes_width' ) ) {
	function seohub_shortcodes_width($w="") {
		return array(
			"title" => esc_html__("Width", "seohub"),
			"divider" => true,
			"value" => $w,
			"type" => "text"
		);
	}
}
if ( !function_exists( 'seohub_shortcodes_height' ) ) {
	function seohub_shortcodes_height($h='') {
		global $SEOHUB_GLOBALS;
		return array(
			"title" => esc_html__("Height", "seohub"),
			"desc" => wp_kses( __("Width (in pixels or percent) and height (only in pixels) of element", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
			"value" => $h,
			"type" => "text"
		);
	}
}

/* Theme setup section
-------------------------------------------------------------------- */

if ( !function_exists( 'seohub_shortcodes_settings_theme_setup' ) ) {
//	if ( seohub_vc_is_frontend() )
	if ( (isset($_GET['vc_editable']) && $_GET['vc_editable']=='true') || (isset($_GET['vc_action']) && $_GET['vc_action']=='vc_inline') )
		add_action( 'seohub_action_before_init_theme', 'seohub_shortcodes_settings_theme_setup', 20 );
	else
		add_action( 'seohub_action_after_init_theme', 'seohub_shortcodes_settings_theme_setup' );
	function seohub_shortcodes_settings_theme_setup() {
		if (seohub_shortcodes_is_used()) {
			global $SEOHUB_GLOBALS;

			// Sort templates alphabetically
			ksort($SEOHUB_GLOBALS['registered_templates']);

			// Prepare arrays 
			$SEOHUB_GLOBALS['sc_params'] = array(
			
				// Current element id
				'id' => array(
					"title" => esc_html__("Element ID", "seohub"),
					"desc" => wp_kses( __("ID for current element", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
					"divider" => true,
					"value" => "",
					"type" => "text"
				),
			
				// Current element class
				'class' => array(
					"title" => esc_html__("Element CSS class", "seohub"),
					"desc" => wp_kses( __("CSS class for current element (optional)", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
					"value" => "",
					"type" => "text"
				),
			
				// Current element style
				'css' => array(
					"title" => esc_html__("CSS styles", "seohub"),
					"desc" => wp_kses( __("Any additional CSS rules (if need)", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
					"value" => "",
					"type" => "text"
				),
			
			
				// Switcher choises
				'list_styles' => array(
					'ul'	=> esc_html__('Unordered', 'seohub'),
					'ol'	=> esc_html__('Ordered', 'seohub'),
					'iconed'=> esc_html__('Iconed', 'seohub')
				),
				'yes_no'	=> seohub_get_list_yesno(),
				'on_off'	=> seohub_get_list_onoff(),
				'dir' 		=> seohub_get_list_directions(),
				'align'		=> seohub_get_list_alignments(),
				'float'		=> seohub_get_list_floats(),
				'show_hide'	=> seohub_get_list_showhide(),
				'sorting' 	=> seohub_get_list_sortings(),
				'ordering' 	=> seohub_get_list_orderings(),
				'shapes'	=> seohub_get_list_shapes(),
				'sizes'		=> seohub_get_list_sizes(),
				'sliders'	=> seohub_get_list_sliders(),
				'categories'=> seohub_get_list_categories(),
				'columns'	=> seohub_get_list_columns(),
				'images'	=> array_merge(array('none'=>"none"), seohub_get_list_files("images/icons", "png")),
				'icons'		=> array_merge(array("inherit", "none"), seohub_get_list_icons()),
				'locations'	=> seohub_get_list_dedicated_locations(),
				'filters'	=> seohub_get_list_portfolio_filters(),
				'formats'	=> seohub_get_list_post_formats_filters(),
				'hovers'	=> seohub_get_list_hovers(true),
				'hovers_dir'=> seohub_get_list_hovers_directions(true),
				'schemes'	=> seohub_get_list_color_schemes(true),
				'animations'		=> seohub_get_list_animations_in(),
				'margins' 			=> seohub_get_list_margins(true),
				'blogger_styles'	=> seohub_get_list_templates_blogger(),
				'forms'				=> seohub_get_list_templates_forms(),
				'posts_types'		=> seohub_get_list_posts_types(),
				'googlemap_styles'	=> seohub_get_list_googlemap_styles(),
				'field_types'		=> seohub_get_list_field_types(),
				'label_positions'	=> seohub_get_list_label_positions()
			);

			$SEOHUB_GLOBALS['sc_params']['animation'] = array(
				"title" => esc_html__("Animation",  'seohub'),
				"desc" => wp_kses( __('Select animation while object enter in the visible area of page',  'seohub'), $SEOHUB_GLOBALS['allowed_tags'] ),
				"value" => "none",
				"type" => "select",
				"options" => $SEOHUB_GLOBALS['sc_params']['animations']
			);
			$SEOHUB_GLOBALS['sc_params']['top'] = array(
				"title" => esc_html__("Top margin",  'seohub'),
				"divider" => true,
				"value" => "inherit",
				"type" => "select",
				"options" => $SEOHUB_GLOBALS['sc_params']['margins']
			);
			$SEOHUB_GLOBALS['sc_params']['bottom'] = array(
				"title" => esc_html__("Bottom margin",  'seohub'),
				"value" => "inherit",
				"type" => "select",
				"options" => $SEOHUB_GLOBALS['sc_params']['margins']
			);
			$SEOHUB_GLOBALS['sc_params']['left'] = array(
				"title" => esc_html__("Left margin",  'seohub'),
				"value" => "inherit",
				"type" => "select",
				"options" => $SEOHUB_GLOBALS['sc_params']['margins']
			);
			$SEOHUB_GLOBALS['sc_params']['right'] = array(
				"title" => esc_html__("Right margin",  'seohub'),
				"desc" => wp_kses( __("Margins around this shortcode", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
				"value" => "inherit",
				"type" => "select",
				"options" => $SEOHUB_GLOBALS['sc_params']['margins']
			);

			$SEOHUB_GLOBALS['sc_params'] = apply_filters('seohub_filter_shortcodes_params', $SEOHUB_GLOBALS['sc_params']);

	
			// Shortcodes list
			//------------------------------------------------------------------
			$SEOHUB_GLOBALS['shortcodes'] = array();
			
			// Add shortcodes
			do_action('seohub_action_shortcodes_list');

			// Sort shortcodes list
			ksort($SEOHUB_GLOBALS['shortcodes']);
		}
	}
}
?>