<?php
$output = $color = $size = $icon = $target = $href = $el_class = $title = $position = $align = $css_animation = '';
extract( shortcode_atts( array(
	'color' => 'wpb_button',
	'size' => '',
	'icon' => 'none',
	'target' => '_self',
	'href' => '',
	'el_class' => '',
	'title' => __( 'Text on the button', "js_composer" ),
	'position' => '',
	'align' => '',
	'css_animation' => ''
), $atts ) );
$a_class = '';

if ( $el_class != '' ) {
	$tmp_class = explode( " ", strtolower( $el_class ) );
	$tmp_class = str_replace( ".", "", $tmp_class );
	if ( in_array( "prettyphoto", $tmp_class ) ) {
		wp_enqueue_script( 'prettyphoto' );
		wp_enqueue_style( 'prettyphoto' );
		$a_class .= ' prettyphoto';
		$el_class = str_ireplace( "prettyphoto", "", $el_class );
	}
	if ( in_array( "pull-right", $tmp_class ) && $href != '' ) {
		$a_class .= ' pull-right';
		$el_class = str_ireplace( "pull-right", "", $el_class );
	}
	if ( in_array( "pull-left", $tmp_class ) && $href != '' ) {
		$a_class .= ' pull-left';
		$el_class = str_ireplace( "pull-left", "", $el_class );
	}
}

$target = ( $target != '' ) ? ' target="' . $target . '"' : '';

$color = ( $color != '' ) ? ' wpb_' . $color : '';
$size = ( $size != '' && $size != 'wpb_regularsize' ) ? ' wpb_' . $size : ' ' . $size;
$icon = ( $icon != '' && $icon != 'none' ) ? ' ' . $icon : '';
$i_icon = ( $icon != '' ) ? ' <i class="icon"> </i>' : '';
$position = ( $position != '' ) ? ' ' . $position . '-button-position' : '';
$el_class = $this->getExtraClass( $el_class );
$animations = $this->getExtraClass(MAD_VC_CONFIG::getCSSAnimation($css_animation));
$css_class = apply_filters( VC_SHORTCODE_CUSTOM_CSS_FILTER_TAG, 'wpb_button ' . $color . $size . $icon . $el_class . $animations . $position, $this->settings['base'], $atts );

ob_start() ?>

<?php if ($align != 'align-left'): ?>
	<div class="<?php echo esc_attr($align) ?>">
<?php endif; ?>

	<a class="<?php echo esc_attr($a_class) . esc_attr($css_class) ?>" title="<?php echo esc_attr($title) ?>" href="<?php echo esc_url($href) ?>" <?php echo $target ?>>
		<span><?php echo $title . $i_icon ?></span>
	</a>

<?php if ($align != 'align-left'): ?>
	</div>
<?php endif; ?>

<?php echo ob_get_clean();

