
­­­­­­­­­­­­­­­­­­
<!DOCTYPE html>
<html>
<?php
/**
 * Shortcode Progress Bars config
 *
 * @link       https://codesupply.co/plugins/basic-shortcodes/
 * @since      1.0.0
 *
 * @package    Basic Shortcodes
 * @subpackage Templates
 */

/**
 * Progress Bars
 */
bsc_register_shortcode( array(
	'name'			=> 'progressbars',
	'title'			=> esc_html__( 'Progress Bars', 'basic-shortcodes' ),
	'priority'		=> 60,
	'base'			=> 'bsc_progressbar',
	'autoregister'	=> true,
	'fields' 		=> array(
		array(
			'type'		=> 'section',
			'label'		=> esc_html__( 'Options', 'basic-shortcodes' ),
		),
		array(
			'type'		=> 'input',
			'name'		=> 'value',
			'label'		=> esc_html__( 'Value', 'basic-shortcodes' ),
			'default'	=> '25',
			'suffix'	=> ' %',
			'desc'		=> '(0-100)',
		),
		array(
			'type'		=> 'section',
			'label'		=> esc_html__( 'Style', 'basic-shortcodes' ),
		),
		array(
			'type'		=> 'input',
			'name'		=> 'height',
			'label'		=> esc_html__( 'Height (thickness)', 'basic-shortcodes' ),
			'default'	=> '20',
			'suffix'	=> ' px',
		),
		array(
			'type'		=> 'radio',
			'name'		=> 'color',
			'label'		=> esc_html__( 'Color', 'basic-shortcodes' ),
			'style'		=> 'vertical',
			'default'	=> 'primary',
			'options'	=> array(
				'primary'	=> esc_html__( 'Primary', 'basic-shortcodes' ),
				'secondary'	=> esc_html__( 'Secondary', 'basic-shortcodes' ),
				'success'	=> esc_html__( 'Success', 'basic-shortcodes' ),
				'info'		=> esc_html__( 'Info', 'basic-shortcodes' ),
				'warning'	=> esc_html__( 'Warning', 'basic-shortcodes' ),
				'danger'	=> esc_html__( 'Danger', 'basic-shortcodes' ),
			),
		),
		array(
			'type'		=> 'checkbox',
			'name'		=> 'display_value',
			'label'		=> esc_html__( 'Display Value', 'basic-shortcodes' ),
			'default'	=> false,
		),
		array(
			'type'		=> 'checkbox',
			'name'		=> 'striped',
			'label'		=> esc_html__( 'Striped', 'basic-shortcodes' ),
			'default'	=> false,
		),
		array(
			'type'		=> 'checkbox',
			'name'		=> 'animated',
			'label'		=> esc_html__( 'Animated', 'basic-shortcodes' ),
			'default'	=> false,
		),
	),
) );


/**
 * Progress Bar Shortcode
 *
 * @param array  $output    Shortcode HTML.
 * @param array  $atts      User defined attributes in shortcode tag.
 * @param string $content   Shorcode tag content.
 * @return string           Shortcode result HTML.
 */
function bsc_progressbar_shortcode( $output, $atts, $content ) {

	// Value.
	$atts['value'] = $atts['value'] > 100 ? 100 : $atts['value'];

	// Display value.
	$display_value = ( 'true' === $atts['display_value'] ) ? $atts['value'] . '%' : '';

	// Striped and animated.
	$class = 'progress-bar';
	$class .= ( 'true' === $atts['striped'] ) ? ' progress-bar-striped' : '';
	$class .= ( 'true' === $atts['animated'] ) ? ' progress-bar-animated' : '';

	// Color.
	$class .= sprintf( ' bg-%s', $atts['color'] );

	$output = sprintf(
		'<div class="bsc-progress progress">
			<div class="%s" role="progressbar" style="width: %3$s%%; height: %2$spx;" aria-valuenow="%3$s" aria-valuemin="0" aria-valuemax="100">%4$s</div>
		</div>',
		$class,
		$atts['height'],
		$atts['value'],
		$display_value
	);

	return $output;
}
add_filter( 'bsc_progressbar_shortcode', 'bsc_progressbar_shortcode', 10, 3 );
