<?php

/* Theme setup section
-------------------------------------------------------------------- */
if (!function_exists('seohub_sc_quote_theme_setup')) {
	add_action( 'seohub_action_before_init_theme', 'seohub_sc_quote_theme_setup' );
	function seohub_sc_quote_theme_setup() {
		add_action('seohub_action_shortcodes_list', 		'seohub_sc_quote_reg_shortcodes');
		if (function_exists('seohub_exists_visual_composer') && seohub_exists_visual_composer())
			add_action('seohub_action_shortcodes_list_vc','seohub_sc_quote_reg_shortcodes_vc');
	}
}



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

/*
[trx_quote id="unique_id" cite="url" title=""]Et adipiscing integer, scelerisque pid, augue mus vel tincidunt porta[/quote]
*/

if (!function_exists('seohub_sc_quote')) {	
	function seohub_sc_quote($atts, $content=null){	
		if (seohub_in_shortcode_blogger()) return '';
		extract(seohub_html_decode(shortcode_atts(array(
			// Individual params
			"title" => "",
			"cite" => "",
            "style_bg" => "green",
			// 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);
		$cite_param = $cite != '' ? ' cite="'.esc_attr($cite).'"' : '';
		$title = $title=='' ? $cite : $title;
		$content = do_shortcode($content);
		if (seohub_substr($content, 0, 2)!='<p') $content = '<p>' . ($content) . '</p>';
		$output = '<blockquote' 
			. ($id ? ' id="'.esc_attr($id).'"' : '') . ($cite_param) 
			. ' class="sc_quote'. (!empty($class) ? ' '.esc_attr($class) : '')
            .' style_'. (!empty($style_bg) ? ''.esc_attr($style_bg) : 'original')
            .'"'
			. (!seohub_param_is_off($animation) ? ' data-animation="'.esc_attr(seohub_get_animation_classes($animation)).'"' : '')
			. ($css!='' ? ' style="'.esc_attr($css).'"' : '') 
			. '>'
				. ($content)
				. ($title == '' ? '' : ('<p class="sc_quote_title">' . ($cite!='' ? '<a href="'.esc_url($cite).'">' : '') . ($title) . ($cite!='' ? '</a>' : '') . '</p>'))
			.'</blockquote>';
		return apply_filters('seohub_shortcode_output', $output, 'trx_quote', $atts, $content);
	}
	seohub_require_shortcode('trx_quote', 'seohub_sc_quote');
}



/* Add shortcode in the internal SC Builder
-------------------------------------------------------------------- */
if ( !function_exists( 'seohub_sc_quote_reg_shortcodes' ) ) {
	//add_action('seohub_action_shortcodes_list', 'seohub_sc_quote_reg_shortcodes');
	function seohub_sc_quote_reg_shortcodes() {
		global $SEOHUB_GLOBALS;
	
		$SEOHUB_GLOBALS['shortcodes']["trx_quote"] = array(
			"title" => esc_html__("Quote", "seohub"),
			"desc" => wp_kses( __("Quote text", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
			"decorate" => false,
			"container" => true,
			"params" => array(
                "style_bg" => array(
                    "title" => esc_html__("Quote's style", "seohub"),
                    "desc" => wp_kses( __("Select quote's style", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
                    "value" => "",
                    "dir" => "horizontal",
                    "options" => array(
                        'green' => esc_html__('Green', 'seohub'),
                        'original' => esc_html__('Original', 'seohub')
                    ),
                    "type" => "checklist"
                ),
				"cite" => array(
					"title" => esc_html__("Quote cite", "seohub"),
					"desc" => wp_kses( __("URL for quote cite", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
					"value" => "",
					"type" => "text"
				),
				"title" => array(
					"title" => esc_html__("Title (author)", "seohub"),
					"desc" => wp_kses( __("Quote title (author name)", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
					"value" => "",
					"type" => "text"
				),
				"_content_" => array(
					"title" => esc_html__("Quote content", "seohub"),
					"desc" => wp_kses( __("Quote content", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
					"rows" => 4,
					"value" => "",
					"type" => "textarea"
				),
				"width" => seohub_shortcodes_width(),
				"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_quote_reg_shortcodes_vc' ) ) {
	//add_action('seohub_action_shortcodes_list_vc', 'seohub_sc_quote_reg_shortcodes_vc');
	function seohub_sc_quote_reg_shortcodes_vc() {
		global $SEOHUB_GLOBALS;
	
		vc_map( array(
			"base" => "trx_quote",
			"name" => esc_html__("Quote", "seohub"),
			"description" => wp_kses( __("Quote text", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
			"category" => esc_html__('Content', 'js_composer'),
			'icon' => 'icon_trx_quote',
			"class" => "trx_sc_single trx_sc_quote",
			"content_element" => true,
			"is_container" => false,
			"show_settings_on_create" => true,
			"params" => array(
                array(
                    "param_name" => "style_bg",
                    "heading" => esc_html__("Quote's style", "seohub"),
                    "description" => wp_kses( __("Select quote's style", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
                    "class" => "",
                    "value" => array(
                        esc_html__('Green', 'seohub') => 'green',
                        esc_html__('Original', 'seohub') => 'original'
                    ),
                    "type" => "dropdown"
                ),
				array(
					"param_name" => "cite",
					"heading" => esc_html__("Quote cite", "seohub"),
					"description" => wp_kses( __("URL for the quote cite link", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
					"class" => "",
					"value" => "",
					"type" => "textfield"
				),
				array(
					"param_name" => "title",
					"heading" => esc_html__("Title (author)", "seohub"),
					"description" => wp_kses( __("Quote title (author name)", "seohub"), $SEOHUB_GLOBALS['allowed_tags'] ),
					"admin_label" => true,
					"class" => "",
					"value" => "",
					"type" => "textfield"
				),
				array(
					"param_name" => "content",
					"heading" => esc_html__("Quote content", "seohub"),
					"description" => wp_kses( __("Quote content", "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_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_Quote extends SEOHUB_VC_ShortCodeSingle {}
	}
}
?>