<?php

class Intense_Heading extends Intense_Shortcode {

	function __construct() {
        parent::__construct();

		global $intense_visions_options;

		$this->title = __( 'Heading', 'intense' );
		$this->description = __( 'When you want to go beyond the theme’s defined headings, the heading shortcode is a powerful tool. It is great for special headings that compliment the design of a specific area of your site.
			<br><br>
			For example, maybe you want a large heading on your landing page that has a different color, alignment, and size than any other heading on your site. These custom situations are easy to accommodate for using the heading shortcode.
			<br><br>
			If you have a heading that is almost what you need, you can choose which HTML tag to use (H1, H2, H3, etc.) as a starting point.', 'intense' );
		$this->category = __( 'Typography', 'intense' );
		$this->show_preview = true;
		$this->preview_content = __( 'Heading Text', 'intense' );
		$this->vc_map_content = 'textfield';
	}

	function shortcode( $atts, $content = null ) {
		global $intense_visions_options;
		extract( shortcode_atts( $this->get_shortcode_defaults( null, $atts ), $atts ) );

		$font_color = intense_get_plugin_color( $font_color );

		if ( is_numeric( $font_size ) ) $font_size .= "px";
		if ( is_numeric( $min_font_size ) ) $min_font_size .= "px";
		if ( is_numeric( $line_height ) ) $line_height .= "px";
		if ( is_numeric( $margin_top ) ) $margin_top .= "px";
  	if ( is_numeric( $margin_bottom ) ) $margin_bottom .= "px";
  	if ( is_numeric( $padding_top ) ) $padding_top .= "px";
  	if ( is_numeric( $padding_bottom ) ) $padding_bottom .= "px";

		$output = '';

		if ( !empty( $font_family ) && FALSE !== strpos( $font_family, 'google|' ) ) {
    	$font_family = str_replace( 'google|', '', $font_family );

    	if ( empty( $GLOBALS['IntenseGoogleFonts'][ $font_family ] ) ) {
    		$GLOBALS['IntenseGoogleFonts'][ $font_family ] = $font_family;

    		$link = intense_create_google_font_link( array( $font_family => array() ) );

    		$output .= '<link href="' . $link . '" rel="stylesheet" type="text/css">';
    	}
    }

		if ( empty( $id ) ) { $id = 'heading-' . rand(); }

		if ( !empty( $responsive ) ) {
			intense_add_script( 'fittext' );

			$max_font_size = '';
			if ( !isset( $min_font_size ) ) $min_font_size = '';			

			if ( !empty( $font_size ) ) $max_font_size = 'maxFontSize: "' . $font_size . '"';
			if ( !empty( $min_font_size ) ) $min_font_size = 'minFontSize: "' . $min_font_size . '"';
			if ( !empty( $max_font_size ) && !empty( $min_font_size ) ) $min_font_size .= ', ';
			if ( empty( $aggressiveness ) ) $aggressiveness = '1';

			$output .= '<script>jQuery(document).ready(function() { jQuery(\'#' . $id . '\').fitText(' . $aggressiveness . ', { ' . $min_font_size . $max_font_size . ' }); });</script>';
			$line_height = 'initial';
		}

		$font_size = ( !empty( $font_size ) ? " font-size: " . $font_size . ';' : '' );
		$line_height = ( !empty( $line_height ) ? " line-height: " . $line_height . ';' : '' );
		$font_color = ( !empty( $font_color ) ? " color: " . $font_color . ';' : '' );
		$align = ( !empty( $align ) ? " text-align: " . $align . ';' : '' );
		$font_weight = ( !empty( $font_weight ) ? " font-weight: " . $font_weight . ';' : '' );
		$margin_top = ( !empty( $margin_top ) ? " margin-top: " . $margin_top . ';' : '' );
		$margin_bottom = ( !empty( $margin_bottom ) ? " margin-bottom: " . $margin_bottom . ';' : '' );
		$padding_top = ( !empty( $padding_top ) ? " padding-top: " . $padding_top . ';' : '' );
		$padding_bottom = ( !empty( $padding_bottom ) ? " padding-bottom: " . $padding_bottom . ';' : '' );
		$font_family = ( !empty( $font_family ) ? " font-family: " . $font_family . ';' : '' );
		$text_transform = ( !empty( $text_transform ) ? " text-transform: " . $text_transform . ';' : '' );
    $id = ( !empty ( $id ) ) ? ' id="' . $id . '"' : '';

		$output .= '<' . $tag . $id . ' class="intense heading' . ( !empty( $class ) ? ' ' . $class : '' ) . '" style="' . $font_color . $font_size . $line_height . $align . $font_weight . $margin_top . $margin_bottom . $padding_top . $padding_bottom . $font_family . $text_transform . ' -webkit-font-smoothing: antialiased;">' . do_shortcode( $content ) . '</' . $tag . '>';

		return $output;
	}
}
