| @@ -5,84 +5,78 @@ | ||
| 5 | 5 | * @package Powerkit |
| 6 | 6 | * @subpackage Templates |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | -// Exit if accessed directly. | |
| 10 | -if ( ! defined( 'ABSPATH' ) ) { | |
| 11 | - exit; | |
| 12 | -} | |
| 13 | - | |
| 14 | 9 | /** |
| 15 | 10 | * Progress Bars |
| 16 | 11 | */ |
| 17 | -add_action( 'init', function () { | |
| 18 | - powerkit_basic_shortcodes_register( array( | |
| 19 | - 'name' => 'progressbars', | |
| 20 | - 'title' => esc_html__( 'Progress Bars', 'powerkit' ), | |
| 21 | - 'priority' => 60, | |
| 22 | - 'base' => 'powerkit_progressbar', | |
| 23 | - 'autoregister' => true, | |
| 24 | - 'fields' => array( | |
| 25 | - array( | |
| 26 | - 'type' => 'section', | |
| 27 | - 'label' => esc_html__( 'Options', 'powerkit' ), | |
| 12 | +powerkit_basic_shortcodes_register( array( | |
| 13 | + 'name' => 'progressbars', | |
| 14 | + 'title' => esc_html__( 'Progress Bars', 'powerkit' ), | |
| 15 | + 'priority' => 60, | |
| 16 | + 'base' => 'powerkit_progressbar', | |
| 17 | + 'autoregister' => true, | |
| 18 | + 'fields' => array( | |
| 19 | + array( | |
| 20 | + 'type' => 'section', | |
| 21 | + 'label' => esc_html__( 'Options', 'powerkit' ), | |
| 22 | + ), | |
| 23 | + array( | |
| 24 | + 'type' => 'input', | |
| 25 | + 'name' => 'value', | |
| 26 | + 'label' => esc_html__( 'Value', 'powerkit' ), | |
| 27 | + 'default' => '25', | |
| 28 | + 'suffix' => ' %', | |
| 29 | + 'desc' => '(0-100)', | |
| 30 | + ), | |
| 31 | + array( | |
| 32 | + 'type' => 'section', | |
| 33 | + 'label' => esc_html__( 'Style', 'powerkit' ), | |
| 34 | + ), | |
| 35 | + array( | |
| 36 | + 'type' => 'input', | |
| 37 | + 'name' => 'height', | |
| 38 | + 'label' => esc_html__( 'Height (thickness)', 'powerkit' ), | |
| 39 | + 'default' => '20', | |
| 40 | + 'suffix' => ' px', | |
| 41 | + ), | |
| 42 | + array( | |
| 43 | + 'type' => 'radio', | |
| 44 | + 'name' => 'color', | |
| 45 | + 'label' => esc_html__( 'Color', 'powerkit' ), | |
| 46 | + 'style' => 'vertical', | |
| 47 | + 'default' => 'primary', | |
| 48 | + 'options' => array( | |
| 49 | + 'primary' => esc_html__( 'Primary', 'powerkit' ), | |
| 50 | + 'secondary' => esc_html__( 'Secondary', 'powerkit' ), | |
| 51 | + 'success' => esc_html__( 'Success', 'powerkit' ), | |
| 52 | + 'info' => esc_html__( 'Info', 'powerkit' ), | |
| 53 | + 'warning' => esc_html__( 'Warning', 'powerkit' ), | |
| 54 | + 'danger' => esc_html__( 'Danger', 'powerkit' ), | |
| 28 | 55 | ), |
| 29 | - array( | |
| 30 | - 'type' => 'input', | |
| 31 | - 'name' => 'value', | |
| 32 | - 'label' => esc_html__( 'Value', 'powerkit' ), | |
| 33 | - 'default' => '25', | |
| 34 | - 'suffix' => ' %', | |
| 35 | - 'desc' => '(0-100)', | |
| 36 | - ), | |
| 37 | - array( | |
| 38 | - 'type' => 'section', | |
| 39 | - 'label' => esc_html__( 'Style', 'powerkit' ), | |
| 40 | - ), | |
| 41 | - array( | |
| 42 | - 'type' => 'input', | |
| 43 | - 'name' => 'height', | |
| 44 | - 'label' => esc_html__( 'Height (thickness)', 'powerkit' ), | |
| 45 | - 'default' => '20', | |
| 46 | - 'suffix' => ' px', | |
| 47 | - ), | |
| 48 | - array( | |
| 49 | - 'type' => 'radio', | |
| 50 | - 'name' => 'color', | |
| 51 | - 'label' => esc_html__( 'Color', 'powerkit' ), | |
| 52 | - 'style' => 'vertical', | |
| 53 | - 'default' => 'primary', | |
| 54 | - 'options' => array( | |
| 55 | - 'primary' => esc_html__( 'Primary', 'powerkit' ), | |
| 56 | - 'secondary' => esc_html__( 'Secondary', 'powerkit' ), | |
| 57 | - 'success' => esc_html__( 'Success', 'powerkit' ), | |
| 58 | - 'info' => esc_html__( 'Info', 'powerkit' ), | |
| 59 | - 'warning' => esc_html__( 'Warning', 'powerkit' ), | |
| 60 | - 'danger' => esc_html__( 'Danger', 'powerkit' ), | |
| 61 | - ), | |
| 62 | - ), | |
| 63 | - array( | |
| 64 | - 'type' => 'checkbox', | |
| 65 | - 'name' => 'display_value', | |
| 66 | - 'label' => esc_html__( 'Display value', 'powerkit' ), | |
| 67 | - 'default' => false, | |
| 68 | - ), | |
| 69 | - array( | |
| 70 | - 'type' => 'checkbox', | |
| 71 | - 'name' => 'striped', | |
| 72 | - 'label' => esc_html__( 'Striped', 'powerkit' ), | |
| 73 | - 'default' => false, | |
| 74 | - ), | |
| 75 | - array( | |
| 76 | - 'type' => 'checkbox', | |
| 77 | - 'name' => 'animated', | |
| 78 | - 'label' => esc_html__( 'Animated', 'powerkit' ), | |
| 79 | - 'default' => false, | |
| 80 | - ), | |
| 81 | 56 | ), |
| 82 | - ) ); | |
| 83 | -}); | |
| 57 | + array( | |
| 58 | + 'type' => 'checkbox', | |
| 59 | + 'name' => 'display_value', | |
| 60 | + 'label' => esc_html__( 'Display value', 'powerkit' ), | |
| 61 | + 'default' => false, | |
| 62 | + ), | |
| 63 | + array( | |
| 64 | + 'type' => 'checkbox', | |
| 65 | + 'name' => 'striped', | |
| 66 | + 'label' => esc_html__( 'Striped', 'powerkit' ), | |
| 67 | + 'default' => false, | |
| 68 | + ), | |
| 69 | + array( | |
| 70 | + 'type' => 'checkbox', | |
| 71 | + 'name' => 'animated', | |
| 72 | + 'label' => esc_html__( 'Animated', 'powerkit' ), | |
| 73 | + 'default' => false, | |
| 74 | + ), | |
| 75 | + ), | |
| 76 | +) ); | |
| 84 | 77 | |
| 78 | + | |
| 85 | 79 | /** |
| 86 | 80 | * Progress Bar Shortcode |
| 87 | 81 | * |
| 88 | 82 | * @param array $output Shortcode HTML. |
| @@ -92,12 +86,12 @@ | ||
| 92 | 86 | */ |
| 93 | 87 | function powerkit_basic_shortcodes_progressbar( $output, $atts, $content ) { |
| 94 | 88 | |
| 95 | 89 | // Value. |
| 96 | - $atts['value'] = ( is_numeric( $atts['value'] ) && $atts['value'] > 100 ) ? 100 : $atts['value']; | |
| 90 | + $atts['value'] = $atts['value'] > 100 ? 100 : $atts['value']; | |
| 97 | 91 | |
| 98 | 92 | // Display value. |
| 99 | - $display_value = ( 'true' === $atts['display_value'] ) ? esc_html( $atts['value'] ) . '%' : ''; | |
| 93 | + $display_value = ( 'true' === $atts['display_value'] ) ? $atts['value'] . '%' : ''; | |
| 100 | 94 | |
| 101 | 95 | // Striped and animated. |
| 102 | 96 | $class = 'pk-progress-bar'; |
| 103 | 97 | $class .= ( 'true' === $atts['striped'] ) ? ' pk-progress-bar-striped' : ''; |
| @@ -103,24 +97,17 @@ | ||
| 103 | 97 | $class .= ( 'true' === $atts['striped'] ) ? ' pk-progress-bar-striped' : ''; |
| 104 | 98 | $class .= ( 'true' === $atts['animated'] ) ? ' pk-progress-bar-animated' : ''; |
| 105 | 99 | |
| 106 | 100 | // Color. |
| 107 | - $class .= ' pk-bg-' . sanitize_html_class( $atts['color'] ); | |
| 101 | + $class .= sprintf( ' pk-bg-%s', $atts['color'] ); | |
| 108 | 102 | |
| 109 | - // Dimensions. Both are cast to a number so they can never break out of the | |
| 110 | - // style attribute. A non-numeric value drops the declaration, which is how | |
| 111 | - // a browser already treats an invalid one. | |
| 112 | - $height_css = is_numeric( $atts['height'] ) ? sprintf( 'height: %spx;', (float) $atts['height'] ) : ''; | |
| 113 | - $width_css = is_numeric( $atts['value'] ) ? sprintf( 'width: %s%%;', (float) $atts['value'] ) : ''; | |
| 114 | - | |
| 115 | 103 | $output = sprintf( |
| 116 | - '<div class="pk-progress" style="%2$s"> | |
| 117 | - <div class="%1$s" role="progressbar" style="%3$s" aria-valuenow="%4$s" aria-valuemin="0" aria-valuemax="100">%5$s</div> | |
| 104 | + '<div class="pk-progress" style="height: %2$spx;"> | |
| 105 | + <div class="%s" role="progressbar" style="width: %3$s%%;" aria-valuenow="%3$s" aria-valuemin="0" aria-valuemax="100">%4$s</div> | |
| 118 | 106 | </div>', |
| 119 | - esc_attr( $class ), | |
| 120 | - esc_attr( $height_css ), | |
| 121 | - esc_attr( $width_css ), | |
| 122 | - esc_attr( $atts['value'] ), | |
| 107 | + $class, | |
| 108 | + $atts['height'], | |
| 109 | + $atts['value'], | |
| 123 | 110 | $display_value |
| 124 | 111 | ); |
| 125 | 112 | |
| 126 | 113 | return $output; |