<?php

/* Theme setup section
-------------------------------------------------------------------- */
if (!function_exists('seohub_sc_price_block_theme_setup')) {
	add_action( 'seohub_action_before_init_theme', 'seohub_sc_price_block_theme_setup' );
	function seohub_sc_price_block_theme_setup() {
		add_action('seohub_action_shortcodes_list', 		'seohub_sc_price_block_reg_shortcodes');
		if (function_exists('seohub_exists_visual_composer') && seohub_exists_visual_composer())
			add_action('seohub_action_shortcodes_list_vc','seohub_sc_price_block_reg_shortcodes_vc');
	}
}



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

if (!function_exists('seohub_sc_price_block')) {	
	function seohub_sc_price_block($atts, $content=null){	
		if (seohub_in_shortcode_blogger()) return '';
		extract(seohub_html_decode(shortcode_atts(array(
			// Individual params
			"style" => 1,
			"title" => "",
			"link" => "",
			"link_text" => "",
			"icon" => "",
			"money" => "",
			"currency" => "$",
			"period" => "",
			"align" => "",
			"scheme" => "",
			// Common params
			"id" => "",
			"class" => "",
			"animation" => "",
			"css" => "",
			"width" => "",
			"height" => "",
			"top" => "",
			"bottom" => "",
			"left" => "",
			"right" => ""
		), $atts)));
		$output = '';
		$class .= ($class ? ' ' : '') . seohub_get_css_position_as_classes($top, $right, $bottom, $left);
		$css .= seohub_get_css_dimensions_from_values($width, $height);
		if ($money) $money = do_shortcode('[trx_price money="'.esc_attr($money).'" period="'.esc_attr($period).'"'.($currency ? ' currency="'.esc_attr($currency).'"' : '').']');
        $content = str_replace(
            array('</p>', '</p>'),
            array('', ''),
            html_entity_decode($content, ENT_COMPAT, 'UTF-8'));
		$content = do_shortcode($content);
		$output = '<div' . ($id ? ' id="'.esc_attr($id).'"' : '') 
					. ' class="sc_price_block sc_price_block_style_'.max(1, min(3, $style))
						. (!empty($class) ? ' '.esc_attr($class) : '')
						. ($scheme && !seohub_param_is_off($scheme) && !seohub_param_is_inherit($scheme) ? ' scheme_'.esc_attr($scheme) : '') 
						. ($align && $align!='none' ? ' align'.esc_attr($align) : '') 
						. '"'
					. ($css!='' ? ' style="'.esc_attr($css).'"' : '')
					. (!seohub_param_is_off($animation) ? ' data-animation="'.esc_attr(seohub_get_animation_classes($animation)).'"' : '')
					. '>'
				. (!empty($title) ? '<div class="sc_price_block_title">'.($title).'</div>' : '')
				. '<div class="sc_price_block_money">'
					. (!empty($icon) ? '<div class="sc_price_block_icon '.esc_attr($icon).'"></div>' : '')
					. ($money)
				. '</div>'
				. (!empty($content) ? '<div class="sc_price_block_description">'.($content).'</div>' : '')
				. (!empty($link_text) ? '<div class="sc_price_block_link">'.do_shortcode('[trx_button style_color="black" link="'.($link ? esc_url($link) : '#').'"]'.($link_text).'[/trx_button]').'</div>' : '')
			. '</div>';
		return apply_filters('seohub_shortcode_output', $output, 'trx_price_block', $atts, $content);
	}
	seohub_require_shortcode('trx_price_block', 'seohub_sc_price_block');
}



/* Add shortcode in the internal SC Builder
-------------------------------------------------------------------- */
if ( !function_exists( 'seohub_sc_price_block_reg_shortcodes' ) ) {
	//add_action('seohub_action_shortcodes_list', 'seohub_sc_price_block_reg_shortcodes');
	function seohub_sc_price_block_reg_shortcodes() {
		global $SEOHUB_GLOBALS;
	
		$SEOHUB_GLOBALS['shortcodes']["trx_price_block"] = array(
			"title" => esc_html__("Price block", "seohub"),
			"desc" => wp_kses( __("Insert price block with title, price and description", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
			"decorate" => false,
			"container" => true,
			"params" => array(
				"style" => array(
					"title" => esc_html__("Block style", "seohub"),
					"desc" => wp_kses( __("Select style for this price block", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
					"value" => 1,
					"options" => seohub_get_list_styles(1, 3),
					"type" => "checklist"
				),
				"title" => array(
					"title" => esc_html__("Title", "seohub"),
					"desc" => wp_kses( __("Block title", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
					"value" => "",
					"type" => "text"
				),
				"link" => array(
					"title" => esc_html__("Link URL", "seohub"),
					"desc" => wp_kses( __("URL for link from button (at bottom of the block)", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
					"value" => "",
					"type" => "text"
				),
				"link_text" => array(
					"title" => esc_html__("Link text", "seohub"),
					"desc" => wp_kses( __("Text (caption) for the link button (at bottom of the block). If empty - button not showed", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
					"value" => "",
					"type" => "text"
				),
				"icon" => array(
					"title" => esc_html__("Icon",  'seohub'),
					"desc" => wp_kses( __('Select icon from Fontello icons set (placed before/instead price)',  'seohub'), $SEOHUB_GLOBALS['allowed_tags'] ),
					"value" => "",
					"type" => "icons",
					"options" => $SEOHUB_GLOBALS['sc_params']['icons']
				),
				"money" => array(
					"title" => esc_html__("Money", "seohub"),
					"desc" => wp_kses( __("Money value (dot or comma separated)", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
					"divider" => true,
					"value" => "",
					"type" => "text"
				),
				"currency" => array(
					"title" => esc_html__("Currency", "seohub"),
					"desc" => wp_kses( __("Currency character", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
					"value" => "$",
					"type" => "text"
				),
				"period" => array(
					"title" => esc_html__("Period", "seohub"),
					"desc" => wp_kses( __("Period text (if need). For example: monthly, daily, etc.", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
					"value" => "",
					"type" => "text"
				),
				"scheme" => array(
					"title" => esc_html__("Color scheme", "seohub"),
					"desc" => wp_kses( __("Select color scheme for this block", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
					"value" => "",
					"type" => "checklist",
					"options" => $SEOHUB_GLOBALS['sc_params']['schemes']
				),
				"align" => array(
					"title" => esc_html__("Alignment", "seohub"),
					"desc" => wp_kses( __("Align price to left or right side", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
					"divider" => true,
					"value" => "",
					"type" => "checklist",
					"dir" => "horizontal",
					"options" => $SEOHUB_GLOBALS['sc_params']['float']
				), 
				"_content_" => array(
					"title" => esc_html__("Description", "seohub"),
					"desc" => wp_kses( __("Description for this price block", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
					"divider" => true,
					"rows" => 4,
					"value" => "",
					"type" => "textarea"
				),
				"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_price_block_reg_shortcodes_vc' ) ) {
	//add_action('seohub_action_shortcodes_list_vc', 'seohub_sc_price_block_reg_shortcodes_vc');
	function seohub_sc_price_block_reg_shortcodes_vc() {
		global $SEOHUB_GLOBALS;
	
		vc_map( array(
			"base" => "trx_price_block",
			"name" => esc_html__("Price block", "seohub"),
			"description" => wp_kses( __("Insert price block with title, price and description", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
			"category" => esc_html__('Content', 'js_composer'),
			'icon' => 'icon_trx_price_block',
			"class" => "trx_sc_single trx_sc_price_block",
			"content_element" => true,
			"is_container" => false,
			"show_settings_on_create" => true,
			"params" => array(
				array(
					"param_name" => "style",
					"heading" => esc_html__("Block style", "seohub"),
					"desc" => wp_kses( __("Select style of this price block", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
					"admin_label" => true,
					"class" => "",
					"std" => 1,
					"value" => array_flip(seohub_get_list_styles(1, 3)),
					"type" => "dropdown"
				),
				array(
					"param_name" => "title",
					"heading" => esc_html__("Title", "seohub"),
					"description" => wp_kses( __("Block title", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
					"admin_label" => true,
					"class" => "",
					"value" => "",
					"type" => "textfield"
				),
				array(
					"param_name" => "link",
					"heading" => esc_html__("Link URL", "seohub"),
					"description" => wp_kses( __("URL for link from button (at bottom of the block)", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
					"class" => "",
					"value" => "",
					"type" => "textfield"
				),
				array(
					"param_name" => "link_text",
					"heading" => esc_html__("Link text", "seohub"),
					"description" => wp_kses( __("Text (caption) for the link button (at bottom of the block). If empty - button not showed", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
					"class" => "",
					"value" => "",
					"type" => "textfield"
				),
				array(
					"param_name" => "icon",
					"heading" => esc_html__("Icon", "seohub"),
					"description" => wp_kses( __("Select icon from Fontello icons set (placed before/instead price)", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
					"class" => "",
					"value" => $SEOHUB_GLOBALS['sc_params']['icons'],
					"type" => "dropdown"
				),
				array(
					"param_name" => "money",
					"heading" => esc_html__("Money", "seohub"),
					"description" => wp_kses( __("Money value (dot or comma separated)", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
					"admin_label" => true,
					"group" => esc_html__('Money', 'seohub'),
					"class" => "",
					"value" => "",
					"type" => "textfield"
				),
				array(
					"param_name" => "currency",
					"heading" => esc_html__("Currency symbol", "seohub"),
					"description" => wp_kses( __("Currency character", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
					"admin_label" => true,
					"group" => esc_html__('Money', 'seohub'),
					"class" => "",
					"value" => "$",
					"type" => "textfield"
				),
				array(
					"param_name" => "period",
					"heading" => esc_html__("Period", "seohub"),
					"description" => wp_kses( __("Period text (if need). For example: monthly, daily, etc.", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
					"admin_label" => true,
					"group" => esc_html__('Money', 'seohub'),
					"class" => "",
					"value" => "",
					"type" => "textfield"
				),
				array(
					"param_name" => "scheme",
					"heading" => esc_html__("Color scheme", "seohub"),
					"description" => wp_kses( __("Select color scheme for this block", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
					"group" => esc_html__('Colors and Images', 'seohub'),
					"class" => "",
					"value" => array_flip($SEOHUB_GLOBALS['sc_params']['schemes']),
					"type" => "dropdown"
				),
				array(
					"param_name" => "align",
					"heading" => esc_html__("Alignment", "seohub"),
					"description" => wp_kses( __("Align price to left or right side", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
					"admin_label" => true,
					"class" => "",
					"value" => array_flip($SEOHUB_GLOBALS['sc_params']['float']),
					"type" => "dropdown"
				),
				array(
					"param_name" => "content",
					"heading" => esc_html__("Description", "seohub"),
					"description" => wp_kses( __("Description for this price block", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
					"class" => "",
					"value" => "",
					"type" => "textarea_html"
				),
				$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_PriceBlock extends SEOHUB_VC_ShortCodeSingle {}
	}
}
?>