<?php

/* Theme setup section
-------------------------------------------------------------------- */
if (!function_exists('seohub_sc_button_theme_setup')) {
	add_action( 'seohub_action_before_init_theme', 'seohub_sc_button_theme_setup' );
	function seohub_sc_button_theme_setup() {
		add_action('seohub_action_shortcodes_list', 		'seohub_sc_button_reg_shortcodes');
		if (function_exists('seohub_exists_visual_composer') && seohub_exists_visual_composer())
			add_action('seohub_action_shortcodes_list_vc','seohub_sc_button_reg_shortcodes_vc');
	}
}



/* Shortcode implementation
-------------------------------------------------------------------- */

/*
[trx_button id="unique_id" type="square|round" fullsize="0|1" style="global|light|dark" size="mini|medium|big|huge|banner" icon="icon-name" link='#' target='']Button caption[/trx_button]
*/

if (!function_exists('seohub_sc_button')) {	
	function seohub_sc_button($atts, $content=null){	
		if (seohub_in_shortcode_blogger()) return '';
		extract(seohub_html_decode(shortcode_atts(array(
			// Individual params
			"type" => "round",
			"style" => "filled",
			"size" => "small",
			"icon" => "",
			"color" => "",
            "style_color" => "normal",
			"bg_color" => "",
			"link" => "",
			"target" => "",
			"align" => "",
			"rel" => "",
			"popup" => "no",
			// Common params
			"id" => "",
			"class" => "",
			"css" => "",
			"animation" => "",
			"width" => "",
			"height" => "",
			"top" => "",
			"bottom" => "",
			"left" => "",
			"right" => ""
		), $atts)));
		$class .= ($class ? ' ' : '') . seohub_get_css_position_as_classes($top, $right, $bottom, $left);
		$css .= seohub_get_css_dimensions_from_values($width, $height)
			. ($color !== '' ? 'color:' . esc_attr($color) .';' : '')
			. ($bg_color !== '' ? 'background-color:' . esc_attr($bg_color) . '; border-color:'. esc_attr($bg_color) .';' : '');
		if (seohub_param_is_on($popup)) seohub_enqueue_popup('magnific');
		$output = '<a href="' . (empty($link) ? '#' : $link) . '"'
			. (!empty($target) ? ' target="'.esc_attr($target).'"' : '')
			. (!empty($rel) ? ' rel="'.esc_attr($rel).'"' : '')
			. (!seohub_param_is_off($animation) ? ' data-animation="'.esc_attr(seohub_get_animation_classes($animation)).'"' : '')
			. ' class="sc_button sc_button_' . esc_attr($type) 
					. ' sc_button_style_' . esc_attr($style) 
					. ' sc_button_size_' . esc_attr($size)
                    . ' sc_button_style_color_' . esc_attr($style_color)
					. ($align && $align!='none' ? ' align'.esc_attr($align) : '') 
					. (!empty($class) ? ' '.esc_attr($class) : '')
					. ($icon!='' ? '  sc_button_iconed '. esc_attr($icon) : '') 
					. (seohub_param_is_on($popup) ? ' sc_popup_link' : '') 
					. '"'
			. ($id ? ' id="'.esc_attr($id).'"' : '') 
			. ($css!='' ? ' style="'.esc_attr($css).'"' : '') 
			. '>'
			. do_shortcode($content)
			. '</a>';
		return apply_filters('seohub_shortcode_output', $output, 'trx_button', $atts, $content);
	}
	seohub_require_shortcode('trx_button', 'seohub_sc_button');
}



/* Add shortcode in the internal SC Builder
-------------------------------------------------------------------- */
if ( !function_exists( 'seohub_sc_button_reg_shortcodes' ) ) {
	//add_action('seohub_action_shortcodes_list', 'seohub_sc_button_reg_shortcodes');
	function seohub_sc_button_reg_shortcodes() {
		global $SEOHUB_GLOBALS;
	
		$SEOHUB_GLOBALS['shortcodes']["trx_button"] = array(
			"title" => esc_html__("Button", "seohub"),
			"desc" => wp_kses( __("Button with link", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
			"decorate" => false,
			"container" => true,
			"params" => array(
				"_content_" => array(
					"title" => esc_html__("Caption", "seohub"),
					"desc" => wp_kses( __("Button caption", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
					"value" => "",
					"type" => "text"
				),
				"type" => array(
					"title" => esc_html__("Button's shape", "seohub"),
					"desc" => wp_kses( __("Select button's shape", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
					"value" => "square",
					"size" => "medium",
					"options" => array(
						'square' => esc_html__('Square', 'seohub'),
						'round' => esc_html__('Round', 'seohub')
					),
					"type" => "switch"
				), 
				"style" => array(
					"title" => esc_html__("Button's style", "seohub"),
					"desc" => wp_kses( __("Select button's style", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
					"value" => "default",
					"dir" => "horizontal",
					"options" => array(
						'filled' => esc_html__('Filled', 'seohub'),
						'border' => esc_html__('Border', 'seohub')
					),
					"type" => "checklist"
				),
                "style_color" => array(
                    "title" => esc_html__("Button's style color", "seohub"),
                    "desc" => wp_kses( __("Select button's style color", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
                    "value" => "default",
                    "dir" => "horizontal",
                    "options" => array(
                        'normal' => esc_html__('Normal', 'seohub'),
                        'black' => esc_html__('Black', 'seohub')
                    ),
                    "type" => "checklist"
                ),
                "size" => array(
					"title" => esc_html__("Button's size", "seohub"),
					"desc" => wp_kses( __("Select button's size", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
					"value" => "small",
					"dir" => "horizontal",
					"options" => array(
						'small' => esc_html__('Small', 'seohub'),
						'medium' => esc_html__('Medium', 'seohub'),
						'large' => esc_html__('Large', 'seohub')
					),
					"type" => "checklist"
				), 
				"icon" => array(
					"title" => esc_html__("Button's icon",  'seohub'),
					"desc" => wp_kses( __('Select icon for the title from Fontello icons set',  'seohub'), $SEOHUB_GLOBALS['allowed_tags'] ),
					"value" => "",
					"type" => "icons",
					"options" => $SEOHUB_GLOBALS['sc_params']['icons']
				),
				"color" => array(
					"title" => esc_html__("Button's text color", "seohub"),
					"desc" => wp_kses( __("Any color for button's caption", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
					"std" => "",
					"value" => "",
					"type" => "color"
				),
				"bg_color" => array(
					"title" => esc_html__("Button's backcolor", "seohub"),
					"desc" => wp_kses( __("Any color for button's background", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
					"value" => "",
					"type" => "color"
				),
				"align" => array(
					"title" => esc_html__("Button's alignment", "seohub"),
					"desc" => wp_kses( __("Align button to left, center or right", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
					"value" => "none",
					"type" => "checklist",
					"dir" => "horizontal",
					"options" => $SEOHUB_GLOBALS['sc_params']['align']
				), 
				"link" => array(
					"title" => esc_html__("Link URL", "seohub"),
					"desc" => wp_kses( __("URL for link on button click", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
					"divider" => true,
					"value" => "",
					"type" => "text"
				),
				"target" => array(
					"title" => esc_html__("Link target", "seohub"),
					"desc" => wp_kses( __("Target for link on button click", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
					"dependency" => array(
						'link' => array('not_empty')
					),
					"value" => "",
					"type" => "text"
				),
				"popup" => array(
					"title" => esc_html__("Open link in popup", "seohub"),
					"desc" => wp_kses( __("Open link target in popup window", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
					"dependency" => array(
						'link' => array('not_empty')
					),
					"value" => "no",
					"type" => "switch",
					"options" => $SEOHUB_GLOBALS['sc_params']['yes_no']
				), 
				"rel" => array(
					"title" => esc_html__("Rel attribute", "seohub"),
					"desc" => wp_kses( __("Rel attribute for button's link (if need)", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
					"dependency" => array(
						'link' => array('not_empty')
					),
					"value" => "",
					"type" => "text"
				),
				"width" => seohub_shortcodes_width(),
				"height" => seohub_shortcodes_height(),
				"top" => $SEOHUB_GLOBALS['sc_params']['top'],
				"bottom" => $SEOHUB_GLOBALS['sc_params']['bottom'],
				"left" => $SEOHUB_GLOBALS['sc_params']['left'],
				"right" => $SEOHUB_GLOBALS['sc_params']['right'],
				"id" => $SEOHUB_GLOBALS['sc_params']['id'],
				"class" => $SEOHUB_GLOBALS['sc_params']['class'],
				"animation" => $SEOHUB_GLOBALS['sc_params']['animation'],
				"css" => $SEOHUB_GLOBALS['sc_params']['css']
			)
		);
	}
}


/* Add shortcode in the VC Builder
-------------------------------------------------------------------- */
if ( !function_exists( 'seohub_sc_button_reg_shortcodes_vc' ) ) {
	//add_action('seohub_action_shortcodes_list_vc', 'seohub_sc_button_reg_shortcodes_vc');
	function seohub_sc_button_reg_shortcodes_vc() {
		global $SEOHUB_GLOBALS;
	
		vc_map( array(
			"base" => "trx_button",
			"name" => esc_html__("Button", "seohub"),
			"description" => wp_kses( __("Button with link", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
			"category" => esc_html__('Content', 'js_composer'),
			'icon' => 'icon_trx_button',
			"class" => "trx_sc_single trx_sc_button",
			"content_element" => true,
			"is_container" => false,
			"show_settings_on_create" => true,
			"params" => array(
				array(
					"param_name" => "content",
					"heading" => esc_html__("Caption", "seohub"),
					"description" => wp_kses( __("Button caption", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
					"class" => "",
					"value" => "",
					"type" => "textfield"
				),
				array(
					"param_name" => "type",
					"heading" => esc_html__("Button's shape", "seohub"),
					"description" => wp_kses( __("Select button's shape", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
					"class" => "",
					"value" => array(
                        esc_html__('Round', 'seohub') => 'round',
						esc_html__('Square', 'seohub') => 'square'

					),
					"type" => "dropdown"
				),
				array(
					"param_name" => "style",
					"heading" => esc_html__("Button's style", "seohub"),
					"description" => wp_kses( __("Select button's style", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
					"class" => "",
					"value" => array(
						esc_html__('Filled', 'seohub') => 'filled',
						esc_html__('Border', 'seohub') => 'border'
					),
					"type" => "dropdown"
				),
                array(
                    "param_name" => "style_color",
                    "heading" => esc_html__("Button's style color", "seohub"),
                    "description" => wp_kses( __("Select button's style color", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
                    "class" => "",
                    "value" => array(
                        esc_html__('Normal', 'seohub') => 'normal',
                        esc_html__('Black', 'seohub') => 'black'
                    ),
                    "type" => "dropdown"
                ),
				array(
					"param_name" => "size",
					"heading" => esc_html__("Button's size", "seohub"),
					"description" => wp_kses( __("Select button's size", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
					"admin_label" => true,
					"class" => "",
					"value" => array(
						esc_html__('Small', 'seohub') => 'small',
						esc_html__('Medium', 'seohub') => 'medium',
						esc_html__('Large', 'seohub') => 'large'
					),
					"type" => "dropdown"
				),
				array(
					"param_name" => "icon",
					"heading" => esc_html__("Button's icon", "seohub"),
					"description" => wp_kses( __("Select icon for the title from Fontello icons set", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
					"class" => "",
					"value" => $SEOHUB_GLOBALS['sc_params']['icons'],
					"type" => "dropdown"
				),
				array(
					"param_name" => "color",
					"heading" => esc_html__("Button's text color", "seohub"),
					"description" => wp_kses( __("Any color for button's caption", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
					"class" => "",
					"value" => "",
					"type" => "colorpicker"
				),
				array(
					"param_name" => "bg_color",
					"heading" => esc_html__("Button's backcolor", "seohub"),
					"description" => wp_kses( __("Any color for button's background", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
					"class" => "",
					"value" => "",
					"type" => "colorpicker"
				),
				array(
					"param_name" => "align",
					"heading" => esc_html__("Button's alignment", "seohub"),
					"description" => wp_kses( __("Align button to left, center or right", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
					"class" => "",
					"value" => array_flip($SEOHUB_GLOBALS['sc_params']['align']),
					"type" => "dropdown"
				),
				array(
					"param_name" => "link",
					"heading" => esc_html__("Link URL", "seohub"),
					"description" => wp_kses( __("URL for the link on button click", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
					"class" => "",
					"group" => esc_html__('Link', 'seohub'),
					"value" => "",
					"type" => "textfield"
				),
				array(
					"param_name" => "target",
					"heading" => esc_html__("Link target", "seohub"),
					"description" => wp_kses( __("Target for the link on button click", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
					"class" => "",
					"group" => esc_html__('Link', 'seohub'),
					"value" => "",
					"type" => "textfield"
				),
				array(
					"param_name" => "popup",
					"heading" => esc_html__("Open link in popup", "seohub"),
					"description" => wp_kses( __("Open link target in popup window", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
					"class" => "",
					"group" => esc_html__('Link', 'seohub'),
					"value" => array(esc_html__('Open in popup', 'seohub') => 'yes'),
					"type" => "checkbox"
				),
				array(
					"param_name" => "rel",
					"heading" => esc_html__("Rel attribute", "seohub"),
					"description" => wp_kses( __("Rel attribute for the button's link (if need", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
					"class" => "",
					"group" => esc_html__('Link', 'seohub'),
					"value" => "",
					"type" => "textfield"
				),
				$SEOHUB_GLOBALS['vc_params']['id'],
				$SEOHUB_GLOBALS['vc_params']['class'],
				$SEOHUB_GLOBALS['vc_params']['animation'],
				$SEOHUB_GLOBALS['vc_params']['css'],
				seohub_vc_width(),
				seohub_vc_height(),
				$SEOHUB_GLOBALS['vc_params']['margin_top'],
				$SEOHUB_GLOBALS['vc_params']['margin_bottom'],
				$SEOHUB_GLOBALS['vc_params']['margin_left'],
				$SEOHUB_GLOBALS['vc_params']['margin_right']
			),
			'js_view' => 'VcTrxTextView'
		) );
		
		class WPBakeryShortCode_Trx_Button extends SEOHUB_VC_ShortCodeSingle {}
	}
}
?>