/** * Progress Bar * simple shortcode that displays a progress bar * @author Chris Reynolds * @since 0.1 * @param string $progress REQUIRED displays the actual progress bar in % or in x/y * usage: [wppb progress=50] or [wppb progress=500/1000] * @param string $option OPTIONAL calls various options. These can be user-input (uses CSS classes, so anything a user adds to their CSS could * potentially be used as an option) or any of the pre-defined options/styles. Included options (as of 1.0.1): candystripes, animated-candystripes, * red * usage: [wppb progress=50 option="red candystripes"] * usage: [wppb progress=50 option=animated-candystripes] * @param string $percent OPTIONAL displays the percentage either on the bar itself, or after the progress bar, depending on which parameter is used. * Options are 'after' and 'inside'. * usage: [wppb progress=50 percent=after] * @param bool $fullwidth OPTIONAL if present (really, if this is in the shortcode at all), will stretch the progress bar to 100% width * usage: [wppb progress=50 fullwidth=true] * @param string $color OPTIONAL sets a color for the progress bar that overrides the default color. can be used as a starting color for $gradient * usage: [wppb progress=50 color=ff0000] * usage: [wppb progress=50 color=ff0000 gradient=.1] * @param string $gradient OPTIONAL @uses $color adds an end color that is the number of degrees offset from the $color parameter and uses it for a * gradient * $color parameter is REQUIRED for $gradient * @uses wppb_check_pos * usage: [wppb progress=50 color=ff0000 gradient=.1] */ function wppb($atts) { extract(shortcode_atts(array('progress' => '', 'option' => '', 'percent' => '', 'location' => '', 'fullwidth' => '', 'color' => '', 'gradient' => '', 'endcolor' => '', 'text' => ''), $atts)); $wppb_check_results = wppb_check_pos($progress); // check the progress for a slash, indicating a fraction instead of a percent $percent = $wppb_check_results[0]; $width = $wppb_check_results[1]; /** * if percent is set instead of location, set the location value to be the same as percent */ if (isset($atts['percent']) && !isset($atts['location'])) { $location = $atts['percent']; } elseif (isset($atts['location'])) { $location = $atts['location']; } /** * if there's custom text and no location has been defined, make the location inside */ if ($text && !$location) { $location = 'inside'; } /** * sanitize any text content */ if (isset($atts['text'])) { $text = strip_tags($atts['text']); } /** * figure out gradient stuff */ $gradient_end = null; if (isset($atts['endcolor'])) { $gradient_end = $atts['endcolor']; } if (isset($atts['gradient']) && isset($atts['color'])) { // if a color AND gradient is set (gradient won't work without the starting color) $gradient_end = wppb_brightness($atts['color'], $atts['gradient']); } if (isset($atts['fullwidth'])) { $fullwidth = true; } $progress = $wppb_check_results[0]; /** * get the progress bar */ $wppb_output = wppb_get_progress_bar($location, $text, $progress, $option, $width, $fullwidth, $color, $gradient, $gradient_end); return $wppb_output; }
public function widget($args, $instance) { extract($args); if (isset($instance['title'])) { $title = apply_filters('widget_title', $instance['title']); } else { $title = ''; } if (isset($instance['progress'])) { $progress = $instance['progress']; } else { $progress = ''; } if (isset($instance['color'])) { $color = $instance['color']; } else { $color = ''; } // a dropdown if (isset($instance['candystripe'])) { $candystripe = $instance['candystripe']; } else { $candystripe = false; } if (isset($instance['location'])) { $location = $instance['location']; } else { $location = ''; } if (isset($instance['text'])) { $text = $instance['text']; } else { $text = ''; } if (isset($instance['description'])) { $description = $instance['description']; } else { $text = ''; } echo $args['before_widget']; if (!empty($title)) { echo $args['before_title'] . esc_attr($title) . $args['after_title']; } $wppb_check_results = wppb_check_pos($progress); // check the progress for a slash, indicating a fraction instead of a percent $percent = $wppb_check_results[0]; $width = $wppb_check_results[1]; if ('none' == $location) { $location = null; } $option = null; if ($color) { $option .= $color; } if ($candystripe) { $option .= ' ' . $candystripe; } $progress = $percent; $the_progress_bar = wppb_get_progress_bar($location, $text, $progress, $option, $width, 'true'); echo $the_progress_bar; echo wpautop(wp_kses_post($description)); echo $args['after_widget']; }