<?php

/* Theme setup section
-------------------------------------------------------------------- */
if (!function_exists('seohub_sc_columns_theme_setup')) {
	add_action( 'seohub_action_before_init_theme', 'seohub_sc_columns_theme_setup' );
	function seohub_sc_columns_theme_setup() {
		add_action('seohub_action_shortcodes_list', 		'seohub_sc_columns_reg_shortcodes');
		if (function_exists('seohub_exists_visual_composer') && seohub_exists_visual_composer())
			add_action('seohub_action_shortcodes_list_vc','seohub_sc_columns_reg_shortcodes_vc');
	}
}



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

/*
[trx_columns id="unique_id" count="number"]
	[trx_column_item id="unique_id" span="2 - number_columns"]Et adipiscing integer, scelerisque pid, augue mus vel tincidunt porta, odio arcu vut natoque dolor ut, enim etiam vut augue. Ac augue amet quis integer ut dictumst? Elit, augue vut egestas! Tristique phasellus cursus egestas a nec a! Sociis et? Augue velit natoque, amet, augue. Vel eu diam, facilisis arcu.[/trx_column_item]
	[trx_column_item]A pulvinar ut, parturient enim porta ut sed, mus amet nunc, in. Magna eros hac montes, et velit. Odio aliquam phasellus enim platea amet. Turpis dictumst ultrices, rhoncus aenean pulvinar? Mus sed rhoncus et cras egestas, non etiam a? Montes? Ac aliquam in nec nisi amet eros! Facilisis! Scelerisque in.[/trx_column_item]
	[trx_column_item]Duis sociis, elit odio dapibus nec, dignissim purus est magna integer eu porta sagittis ut, pid rhoncus facilisis porttitor porta, et, urna parturient mid augue a, in sit arcu augue, sit lectus, natoque montes odio, enim. Nec purus, cras tincidunt rhoncus proin lacus porttitor rhoncus, vut enim habitasse cum magna.[/trx_column_item]
	[trx_column_item]Nec purus, cras tincidunt rhoncus proin lacus porttitor rhoncus, vut enim habitasse cum magna. Duis sociis, elit odio dapibus nec, dignissim purus est magna integer eu porta sagittis ut, pid rhoncus facilisis porttitor porta, et, urna parturient mid augue a, in sit arcu augue, sit lectus, natoque montes odio, enim.[/trx_column_item]
[/trx_columns]
*/

if (!function_exists('seohub_sc_columns')) {	
	function seohub_sc_columns($atts, $content=null){	
		if (seohub_in_shortcode_blogger()) return '';
		extract(seohub_html_decode(shortcode_atts(array(
			// Individual params
			"count" => "2",
			"fluid" => "no",
			"margins" => "yes",
			// 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);
		$count = max(1, min(12, (int) $count));
		global $SEOHUB_GLOBALS;
		$SEOHUB_GLOBALS['sc_columns_counter'] = 1;
		$SEOHUB_GLOBALS['sc_columns_after_span2'] = false;
		$SEOHUB_GLOBALS['sc_columns_after_span3'] = false;
		$SEOHUB_GLOBALS['sc_columns_after_span4'] = false;
		$SEOHUB_GLOBALS['sc_columns_count'] = $count;
		$output = '<div' . ($id ? ' id="'.esc_attr($id).'"' : '') 
				. ' class="columns_wrap sc_columns'
					. ' columns_' . (seohub_param_is_on($fluid) ? 'fluid' : 'nofluid') 
					. (!empty($margins) && seohub_param_is_off($margins) ? ' no_margins' : '') 
					. ' sc_columns_count_' . esc_attr($count)
					. (!empty($class) ? ' '.esc_attr($class) : '') 
				. '"'
				. ($css!='' ? ' style="'.esc_attr($css).'"' : '')
				. (!seohub_param_is_off($animation) ? ' data-animation="'.esc_attr(seohub_get_animation_classes($animation)).'"' : '')
				. '>'
					. do_shortcode($content)
				. '</div>';
		return apply_filters('seohub_shortcode_output', $output, 'trx_columns', $atts, $content);
	}
	seohub_require_shortcode('trx_columns', 'seohub_sc_columns');
}


if (!function_exists('seohub_sc_column_item')) {	
	function seohub_sc_column_item($atts, $content=null) {
		if (seohub_in_shortcode_blogger()) return '';
		extract(seohub_html_decode(shortcode_atts( array(
			// Individual params
			"span" => "1",
			"align" => "",
			"color" => "",
			"bg_color" => "",
			"bg_image" => "",
			"bg_tile" => "no",
			// Common params
			"id" => "",
			"class" => "",
			"css" => "",
			"animation" => ""
		), $atts)));
		$css .= ($align !== '' ? 'text-align:' . esc_attr($align) . ';' : '') 
			. ($color !== '' ? 'color:' . esc_attr($color) . ';' : '');
		$span = max(1, min(11, (int) $span));
		if (!empty($bg_image)) {
			if ($bg_image > 0) {
				$attach = wp_get_attachment_image_src( $bg_image, 'full' );
				if (isset($attach[0]) && $attach[0]!='')
					$bg_image = $attach[0];
			}
		}
		global $SEOHUB_GLOBALS;
		$output = '<div' . ($id ? ' id="'.esc_attr($id).'"' : '') . ' class="column-'.($span > 1 ? esc_attr($span) : 1).'_'.esc_attr($SEOHUB_GLOBALS['sc_columns_count']).' sc_column_item sc_column_item_'.esc_attr($SEOHUB_GLOBALS['sc_columns_counter']) 
					. (!empty($class) ? ' '.esc_attr($class) : '')
					. ($SEOHUB_GLOBALS['sc_columns_counter'] % 2 == 1 ? ' odd' : ' even') 
					. ($SEOHUB_GLOBALS['sc_columns_counter'] == 1 ? ' first' : '') 
					. ($span > 1 ? ' span_'.esc_attr($span) : '') 
					. ($SEOHUB_GLOBALS['sc_columns_after_span2'] ? ' after_span_2' : '') 
					. ($SEOHUB_GLOBALS['sc_columns_after_span3'] ? ' after_span_3' : '') 
					. ($SEOHUB_GLOBALS['sc_columns_after_span4'] ? ' after_span_4' : '') 
					. '"'
					. ($css!='' ? ' style="'.esc_attr($css).'"' : '')
					. (!seohub_param_is_off($animation) ? ' data-animation="'.esc_attr(seohub_get_animation_classes($animation)).'"' : '')
					. '>'
					. ($bg_color!=='' || $bg_image !== '' ? '<div class="sc_column_item_inner" style="'
							. ($bg_color !== '' ? 'background-color:' . esc_attr($bg_color) . ';' : '')
							. ($bg_image !== '' ? 'background-image:url(' . esc_url($bg_image) . ');'.(seohub_param_is_on($bg_tile) ? 'background-repeat:repeat;' : 'background-repeat:no-repeat;background-size:cover;') : '')
							. '">' : '')
						. do_shortcode($content)
					. ($bg_color!=='' || $bg_image !== '' ? '</div>' : '')
					. '</div>';
		$SEOHUB_GLOBALS['sc_columns_counter'] += $span;
		$SEOHUB_GLOBALS['sc_columns_after_span2'] = $span==2;
		$SEOHUB_GLOBALS['sc_columns_after_span3'] = $span==3;
		$SEOHUB_GLOBALS['sc_columns_after_span4'] = $span==4;
		return apply_filters('seohub_shortcode_output', $output, 'trx_column_item', $atts, $content);
	}
	seohub_require_shortcode('trx_column_item', 'seohub_sc_column_item');
}



/* Add shortcode in the internal SC Builder
-------------------------------------------------------------------- */
if ( !function_exists( 'seohub_sc_columns_reg_shortcodes' ) ) {
	//add_action('seohub_action_shortcodes_list', 'seohub_sc_columns_reg_shortcodes');
	function seohub_sc_columns_reg_shortcodes() {
		global $SEOHUB_GLOBALS;
	
		$SEOHUB_GLOBALS['shortcodes']["trx_columns"] = array(
			"title" => esc_html__("Columns", "seohub"),
			"desc" => wp_kses( __("Insert up to 5 columns in your page (post)", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
			"decorate" => true,
			"container" => false,
			"params" => array(
				"fluid" => array(
					"title" => esc_html__("Fluid columns", "seohub"),
					"desc" => wp_kses( __("To squeeze the columns when reducing the size of the window (fluid=yes) or to rebuild them (fluid=no)", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
					"value" => "no",
					"type" => "switch",
					"options" => $SEOHUB_GLOBALS['sc_params']['yes_no']
				), 
				"margins" => array(
					"title" => esc_html__("Margins between columns", "seohub"),
					"desc" => wp_kses( __("Add margins between columns", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
					"value" => "yes",
					"type" => "switch",
					"options" => $SEOHUB_GLOBALS['sc_params']['yes_no']
				), 
				"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']
			),
			"children" => array(
				"name" => "trx_column_item",
				"title" => esc_html__("Column", "seohub"),
				"desc" => wp_kses( __("Column item", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
				"container" => true,
				"params" => array(
					"span" => array(
						"title" => esc_html__("Merge columns", "seohub"),
						"desc" => wp_kses( __("Count merged columns from current", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
						"value" => "",
						"type" => "text"
					),
					"align" => array(
						"title" => esc_html__("Alignment", "seohub"),
						"desc" => wp_kses( __("Alignment text in the column", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
						"value" => "",
						"type" => "checklist",
						"dir" => "horizontal",
						"options" => $SEOHUB_GLOBALS['sc_params']['align']
					),
					"color" => array(
						"title" => esc_html__("Fore color", "seohub"),
						"desc" => wp_kses( __("Any color for objects in this column", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
						"value" => "",
						"type" => "color"
					),
					"bg_color" => array(
						"title" => esc_html__("Background color", "seohub"),
						"desc" => wp_kses( __("Any background color for this column", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
						"value" => "",
						"type" => "color"
					),
					"bg_image" => array(
						"title" => esc_html__("URL for background image file", "seohub"),
						"desc" => wp_kses( __("Select or upload image or write URL from other site for the background", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
						"readonly" => false,
						"value" => "",
						"type" => "media"
					),
					"bg_tile" => array(
						"title" => esc_html__("Tile background image", "seohub"),
						"desc" => wp_kses( __("Do you want tile background image or image cover whole column?", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
						"value" => "no",
						"dependency" => array(
							'bg_image' => array('not_empty')
						),
						"type" => "switch",
						"options" => $SEOHUB_GLOBALS['sc_params']['yes_no']
					),
					"_content_" => array(
						"title" => esc_html__("Column item content", "seohub"),
						"desc" => wp_kses( __("Current column item content", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
						"divider" => true,
						"rows" => 4,
						"value" => "",
						"type" => "textarea"
					),
					"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_columns_reg_shortcodes_vc' ) ) {
	//add_action('seohub_action_shortcodes_list_vc', 'seohub_sc_columns_reg_shortcodes_vc');
	function seohub_sc_columns_reg_shortcodes_vc() {
		global $SEOHUB_GLOBALS;
	
		vc_map( array(
			"base" => "trx_columns",
			"name" => esc_html__("Columns", "seohub"),
			"description" => wp_kses( __("Insert columns with margins", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
			"category" => esc_html__('Content', 'js_composer'),
			'icon' => 'icon_trx_columns',
			"class" => "trx_sc_columns",
			"content_element" => true,
			"is_container" => true,
			"show_settings_on_create" => false,
			"as_parent" => array('only' => 'trx_column_item'),
			"params" => array(
				array(
					"param_name" => "count",
					"heading" => esc_html__("Columns count", "seohub"),
					"description" => wp_kses( __("Number of the columns in the container.", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
					"admin_label" => true,
					"class" => "",
					"value" => "2",
					"type" => "textfield"
				),
				array(
					"param_name" => "fluid",
					"heading" => esc_html__("Fluid columns", "seohub"),
					"description" => wp_kses( __("To squeeze the columns when reducing the size of the window (fluid=yes) or to rebuild them (fluid=no)", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
					"class" => "",
					"value" => array(esc_html__('Fluid columns', 'seohub') => 'yes'),
					"type" => "checkbox"
				),
				array(
					"param_name" => "margins",
					"heading" => esc_html__("Margins between columns", "seohub"),
					"description" => wp_kses( __("Add margins between columns", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
					"class" => "",
					"std" => "yes",
					"value" => array(esc_html__('Disable margins between columns', 'seohub') => 'no'),
					"type" => "checkbox"
				),
				$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']
			),
			'default_content' => '
				[trx_column_item][/trx_column_item]
				[trx_column_item][/trx_column_item]
			',
			'js_view' => 'VcTrxColumnsView'
		) );
		
		
		vc_map( array(
			"base" => "trx_column_item",
			"name" => esc_html__("Column", "seohub"),
			"description" => wp_kses( __("Column item", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
			"show_settings_on_create" => true,
			"class" => "trx_sc_collection trx_sc_column_item",
			"content_element" => true,
			"is_container" => true,
			'icon' => 'icon_trx_column_item',
			"as_child" => array('only' => 'trx_columns'),
			"as_parent" => array('except' => 'trx_columns'),
			"params" => array(
				array(
					"param_name" => "span",
					"heading" => esc_html__("Merge columns", "seohub"),
					"description" => wp_kses( __("Count merged columns from current", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
					"admin_label" => true,
					"class" => "",
					"value" => "",
					"type" => "textfield"
				),
				array(
					"param_name" => "align",
					"heading" => esc_html__("Alignment", "seohub"),
					"description" => wp_kses( __("Alignment text in the column", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
					"class" => "",
					"value" => array_flip($SEOHUB_GLOBALS['sc_params']['align']),
					"type" => "dropdown"
				),
				array(
					"param_name" => "color",
					"heading" => esc_html__("Fore color", "seohub"),
					"description" => wp_kses( __("Any color for objects in this column", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
					"class" => "",
					"value" => "",
					"type" => "colorpicker"
				),
				array(
					"param_name" => "bg_color",
					"heading" => esc_html__("Background color", "seohub"),
					"description" => wp_kses( __("Any background color for this column", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
					"class" => "",
					"value" => "",
					"type" => "colorpicker"
				),
				array(
					"param_name" => "bg_image",
					"heading" => esc_html__("URL for background image file", "seohub"),
					"description" => wp_kses( __("Select or upload image or write URL from other site for the background", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
					"class" => "",
					"value" => "",
					"type" => "attach_image"
				),
				array(
					"param_name" => "bg_tile",
					"heading" => esc_html__("Tile background image", "seohub"),
					"description" => wp_kses( __("Do you want tile background image or image cover whole column?", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
					"class" => "",
					'dependency' => array(
						'element' => 'bg_image',
						'not_empty' => true
					),
					"std" => "no",
					"value" => array(esc_html__('Tile background image', 'seohub') => 'yes'),
					"type" => "checkbox"
				),
				/*
				array(
					"param_name" => "content",
					"heading" => esc_html__("Column's content", "seohub"),
					"description" => wp_kses( __("Content of the current column", "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']
			),
			'js_view' => 'VcTrxColumnItemView'
		) );
		
		class WPBakeryShortCode_Trx_Columns extends SEOHUB_VC_ShortCodeColumns {}
		class WPBakeryShortCode_Trx_Column_Item extends SEOHUB_VC_ShortCodeCollection {}
	}
}
?>