<?php

/* Theme setup section
-------------------------------------------------------------------- */
if (!function_exists('seohub_sc_title_theme_setup')) {
	add_action( 'seohub_action_before_init_theme', 'seohub_sc_title_theme_setup' );
	function seohub_sc_title_theme_setup() {
		add_action('seohub_action_shortcodes_list', 		'seohub_sc_title_reg_shortcodes');
		if (function_exists('seohub_exists_visual_composer') && seohub_exists_visual_composer())
			add_action('seohub_action_shortcodes_list_vc','seohub_sc_title_reg_shortcodes_vc');
	}
}



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

/*
[trx_title id="unique_id" style='regular|iconed' icon='' image='' background="on|off" type="1-6"]Et adipiscing integer, scelerisque pid, augue mus vel tincidunt porta[/trx_title]
*/

if (!function_exists('seohub_sc_title')) {	
	function seohub_sc_title($atts, $content=null){	
		if (seohub_in_shortcode_blogger()) return '';
		extract(seohub_html_decode(shortcode_atts(array(
			// Individual params
			"type" => "1",
			"style" => "regular",
			"align" => "",
			"font_weight" => "",
			"font_size" => "",
			"color" => "",
			"icon" => "",
			"image" => "",
			"picture" => "",
			"image_size" => "small",
			"position" => "left",
			// Common params
			"id" => "",
			"class" => "",
			"animation" => "",
			"css" => "",
			"width" => "",
			"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)
			.($align && $align!='none' && !seohub_param_is_inherit($align) ? 'text-align:' . esc_attr($align) .';' : '')
			.($color ? 'color:' . esc_attr($color) .';' : '')
			.($font_weight && !seohub_param_is_inherit($font_weight) ? 'font-weight:' . esc_attr($font_weight) .';' : '')
			.($font_size   ? 'font-size:' . esc_attr($font_size) .';' : '')
			;
		$type = min(6, max(1, $type));
		if ($picture > 0) {
			$attach = wp_get_attachment_image_src( $picture, 'full' );
			if (isset($attach[0]) && $attach[0]!='')
				$picture = $attach[0];
		}
		$pic = $style!='iconed' 
			? '' 
			: '<span class="sc_title_icon sc_title_icon_'.esc_attr($position).'  sc_title_icon_'.esc_attr($image_size).($icon!='' && $icon!='none' ? ' '.esc_attr($icon) : '').'"'.'>'
				.($picture ? '<img src="'.esc_url($picture).'" alt="" />' : '')
				.(empty($picture) && $image && $image!='none' ? '<img src="'.esc_url(seohub_strpos($image, 'http:')!==false ? $image : seohub_get_file_url('images/icons/'.($image).'.png')).'" alt="" />' : '')
				.'</span>';
		$output = '<h' . esc_attr($type) . ($id ? ' id="'.esc_attr($id).'"' : '')
				. ' class="sc_title sc_title_'.esc_attr($style)
					.($align && $align!='none' && !seohub_param_is_inherit($align) ? ' sc_align_' . esc_attr($align) : '')
					.(!empty($class) ? ' '.esc_attr($class) : '')
					.'"'
				. ($css!='' ? ' style="'.esc_attr($css).'"' : '')
				. (!seohub_param_is_off($animation) ? ' data-animation="'.esc_attr(seohub_get_animation_classes($animation)).'"' : '')
				. '>'
					. ($pic)
					. ($style=='divider' ? '<span class="sc_title_divider_before"'.($color ? ' style="background-color: '.esc_attr($color).'"' : '').'></span>' : '')
					. do_shortcode($content) 
					. ($style=='divider' ? '<span class="sc_title_divider_after"'.($color ? ' style="background-color: '.esc_attr($color).'"' : '').'></span>' : '')
				. '</h' . esc_attr($type) . '>';
		return apply_filters('seohub_shortcode_output', $output, 'trx_title', $atts, $content);
	}
	seohub_require_shortcode('trx_title', 'seohub_sc_title');
}



/* Add shortcode in the internal SC Builder
-------------------------------------------------------------------- */
if ( !function_exists( 'seohub_sc_title_reg_shortcodes' ) ) {
	//add_action('seohub_action_shortcodes_list', 'seohub_sc_title_reg_shortcodes');
	function seohub_sc_title_reg_shortcodes() {
		global $SEOHUB_GLOBALS;
	
		$SEOHUB_GLOBALS['shortcodes']["trx_title"] = array(
			"title" => esc_html__("Title", "seohub"),
			"desc" => wp_kses( __("Create header tag (1-6 level) with many styles", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
			"decorate" => false,
			"container" => true,
			"params" => array(
				"_content_" => array(
					"title" => esc_html__("Title content", "seohub"),
					"desc" => wp_kses( __("Title content", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
					"rows" => 4,
					"value" => "",
					"type" => "textarea"
				),
				"type" => array(
					"title" => esc_html__("Title type", "seohub"),
					"desc" => wp_kses( __("Title type (header level)", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
					"divider" => true,
					"value" => "1",
					"type" => "select",
					"options" => array(
						'1' => esc_html__('Header 1', 'seohub'),
						'2' => esc_html__('Header 2', 'seohub'),
						'3' => esc_html__('Header 3', 'seohub'),
						'4' => esc_html__('Header 4', 'seohub'),
						'5' => esc_html__('Header 5', 'seohub'),
						'6' => esc_html__('Header 6', 'seohub'),
					)
				),
				"style" => array(
					"title" => esc_html__("Title style", "seohub"),
					"desc" => wp_kses( __("Title style", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
					"value" => "regular",
					"type" => "select",
					"options" => array(
						'regular' => esc_html__('Regular', 'seohub'),
						'underline' => esc_html__('Underline', 'seohub'),
						'divider' => esc_html__('Divider', 'seohub'),
						'iconed' => esc_html__('With icon (image)', 'seohub')
					)
				),
				"align" => array(
					"title" => esc_html__("Alignment", "seohub"),
					"desc" => wp_kses( __("Title text alignment", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
					"value" => "",
					"type" => "checklist",
					"dir" => "horizontal",
					"options" => $SEOHUB_GLOBALS['sc_params']['align']
				), 
				"font_size" => array(
					"title" => esc_html__("Font_size", "seohub"),
					"desc" => wp_kses( __("Custom font size. If empty - use theme default", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
					"value" => "",
					"type" => "text"
				),
				"font_weight" => array(
					"title" => esc_html__("Font weight", "seohub"),
					"desc" => wp_kses( __("Custom font weight. If empty or inherit - use theme default", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
					"value" => "",
					"type" => "select",
					"size" => "medium",
					"options" => array(
						'inherit' => esc_html__('Default', 'seohub'),
						'100' => esc_html__('Thin (100)', 'seohub'),
						'300' => esc_html__('Light (300)', 'seohub'),
						'400' => esc_html__('Normal (400)', 'seohub'),
						'600' => esc_html__('Semibold (600)', 'seohub'),
						'700' => esc_html__('Bold (700)', 'seohub'),
						'900' => esc_html__('Black (900)', 'seohub')
					)
				),
				"color" => array(
					"title" => esc_html__("Title color", "seohub"),
					"desc" => wp_kses( __("Select color for the title", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
					"value" => "",
					"type" => "color"
				),
				"icon" => array(
					"title" => esc_html__('Title font icon',  'seohub'),
					"desc" => wp_kses( __("Select font icon for the title from Fontello icons set (if style=iconed)",  'seohub'), $SEOHUB_GLOBALS['allowed_tags'] ),
					"dependency" => array(
						'style' => array('iconed')
					),
					"value" => "",
					"type" => "icons",
					"options" => $SEOHUB_GLOBALS['sc_params']['icons']
				),
				"image" => array(
					"title" => esc_html__('or image icon',  'seohub'),
					"desc" => wp_kses( __("Select image icon for the title instead icon above (if style=iconed)",  'seohub'), $SEOHUB_GLOBALS['allowed_tags'] ),
					"dependency" => array(
						'style' => array('iconed')
					),
					"value" => "",
					"type" => "images",
					"size" => "small",
					"options" => $SEOHUB_GLOBALS['sc_params']['images']
				),
				"picture" => array(
					"title" => esc_html__('or URL for image file', "seohub"),
					"desc" => wp_kses( __("Select or upload image or write URL from other site (if style=iconed)", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
					"dependency" => array(
						'style' => array('iconed')
					),
					"readonly" => false,
					"value" => "",
					"type" => "media"
				),
				"image_size" => array(
					"title" => esc_html__('Image (picture) size', "seohub"),
					"desc" => wp_kses( __("Select image (picture) size (if style='iconed')", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
					"dependency" => array(
						'style' => array('iconed')
					),
					"value" => "small",
					"type" => "checklist",
					"options" => array(
						'small' => esc_html__('Small', 'seohub'),
						'medium' => esc_html__('Medium', 'seohub'),
						'large' => esc_html__('Large', 'seohub')
					)
				),
				"position" => array(
					"title" => esc_html__('Icon (image) position', "seohub"),
					"desc" => wp_kses( __("Select icon (image) position (if style=iconed)", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
					"dependency" => array(
						'style' => array('iconed')
					),
					"value" => "left",
					"type" => "checklist",
					"options" => array(
						'top' => esc_html__('Top', 'seohub'),
						'left' => esc_html__('Left', 'seohub')
					)
				),
				"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_title_reg_shortcodes_vc' ) ) {
	//add_action('seohub_action_shortcodes_list_vc', 'seohub_sc_title_reg_shortcodes_vc');
	function seohub_sc_title_reg_shortcodes_vc() {
		global $SEOHUB_GLOBALS;
	
		vc_map( array(
			"base" => "trx_title",
			"name" => esc_html__("Title", "seohub"),
			"description" => wp_kses( __("Create header tag (1-6 level) with many styles", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
			"category" => esc_html__('Content', 'js_composer'),
			'icon' => 'icon_trx_title',
			"class" => "trx_sc_single trx_sc_title",
			"content_element" => true,
			"is_container" => false,
			"show_settings_on_create" => true,
			"params" => array(
				array(
					"param_name" => "content",
					"heading" => esc_html__("Title content", "seohub"),
					"description" => wp_kses( __("Title content", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
					"class" => "",
					"value" => "",
					"type" => "textarea_html"
				),
				array(
					"param_name" => "type",
					"heading" => esc_html__("Title type", "seohub"),
					"description" => wp_kses( __("Title type (header level)", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
					"admin_label" => true,
					"class" => "",
					"value" => array(
						esc_html__('Header 1', 'seohub') => '1',
						esc_html__('Header 2', 'seohub') => '2',
						esc_html__('Header 3', 'seohub') => '3',
						esc_html__('Header 4', 'seohub') => '4',
						esc_html__('Header 5', 'seohub') => '5',
						esc_html__('Header 6', 'seohub') => '6'
					),
					"type" => "dropdown"
				),
				array(
					"param_name" => "style",
					"heading" => esc_html__("Title style", "seohub"),
					"description" => wp_kses( __("Title style: only text (regular) or with icon/image (iconed)", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
					"admin_label" => true,
					"class" => "",
					"value" => array(
						esc_html__('Regular', 'seohub') => 'regular',
						esc_html__('Underline', 'seohub') => 'underline',
						esc_html__('Divider', 'seohub') => 'divider',
						esc_html__('With icon (image)', 'seohub') => 'iconed'
					),
					"type" => "dropdown"
				),
				array(
					"param_name" => "align",
					"heading" => esc_html__("Alignment", "seohub"),
					"description" => wp_kses( __("Title text alignment", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
					"admin_label" => true,
					"class" => "",
					"value" => array_flip($SEOHUB_GLOBALS['sc_params']['align']),
					"type" => "dropdown"
				),
				array(
					"param_name" => "font_size",
					"heading" => esc_html__("Font size", "seohub"),
					"description" => wp_kses( __("Custom font size. If empty - use theme default", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
					"class" => "",
					"value" => "",
					"type" => "textfield"
				),
				array(
					"param_name" => "font_weight",
					"heading" => esc_html__("Font weight", "seohub"),
					"description" => wp_kses( __("Custom font weight. If empty or inherit - use theme default", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
					"class" => "",
					"value" => array(
						esc_html__('Default', 'seohub') => 'inherit',
						esc_html__('Thin (100)', 'seohub') => '100',
						esc_html__('Light (300)', 'seohub') => '300',
						esc_html__('Normal (400)', 'seohub') => '400',
						esc_html__('Semibold (600)', 'seohub') => '600',
						esc_html__('Bold (700)', 'seohub') => '700',
						esc_html__('Black (900)', 'seohub') => '900'
					),
					"type" => "dropdown"
				),
				array(
					"param_name" => "color",
					"heading" => esc_html__("Title color", "seohub"),
					"description" => wp_kses( __("Select color for the title", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
					"class" => "",
					"value" => "",
					"type" => "colorpicker"
				),
				array(
					"param_name" => "icon",
					"heading" => esc_html__("Title font icon", "seohub"),
					"description" => wp_kses( __("Select font icon for the title from Fontello icons set (if style=iconed)", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
					"class" => "",
					"group" => esc_html__('Icon &amp; Image', 'seohub'),
					'dependency' => array(
						'element' => 'style',
						'value' => array('iconed')
					),
					"value" => $SEOHUB_GLOBALS['sc_params']['icons'],
					"type" => "dropdown"
				),
				array(
					"param_name" => "image",
					"heading" => esc_html__("or image icon", "seohub"),
					"description" => wp_kses( __("Select image icon for the title instead icon above (if style=iconed)", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
					"class" => "",
					"group" => esc_html__('Icon &amp; Image', 'seohub'),
					'dependency' => array(
						'element' => 'style',
						'value' => array('iconed')
					),
					"value" => $SEOHUB_GLOBALS['sc_params']['images'],
					"type" => "dropdown"
				),
				array(
					"param_name" => "picture",
					"heading" => esc_html__("or select uploaded image", "seohub"),
					"description" => wp_kses( __("Select or upload image or write URL from other site (if style=iconed)", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
					"group" => esc_html__('Icon &amp; Image', 'seohub'),
					"class" => "",
					"value" => "",
					"type" => "attach_image"
				),
				array(
					"param_name" => "image_size",
					"heading" => esc_html__("Image (picture) size", "seohub"),
					"description" => wp_kses( __("Select image (picture) size (if style=iconed)", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
					"group" => esc_html__('Icon &amp; Image', 'seohub'),
					"class" => "",
					"value" => array(
						esc_html__('Small', 'seohub') => 'small',
						esc_html__('Medium', 'seohub') => 'medium',
						esc_html__('Large', 'seohub') => 'large'
					),
					"type" => "dropdown"
				),
				array(
					"param_name" => "position",
					"heading" => esc_html__("Icon (image) position", "seohub"),
					"description" => wp_kses( __("Select icon (image) position (if style=iconed)", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
					"group" => esc_html__('Icon &amp; Image', 'seohub'),
					"class" => "",
					"std" => "left",
					"value" => array(
						esc_html__('Top', 'seohub') => 'top',
						esc_html__('Left', 'seohub') => 'left'
					),
					"type" => "dropdown"
				),
				$SEOHUB_GLOBALS['vc_params']['id'],
				$SEOHUB_GLOBALS['vc_params']['class'],
				$SEOHUB_GLOBALS['vc_params']['animation'],
				$SEOHUB_GLOBALS['vc_params']['css'],
				$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_Title extends SEOHUB_VC_ShortCodeSingle {}
	}
}
?>