WordPress.org

Plugin Directory

Changeset 523224


Ignore:
Timestamp:
03/25/12 01:03:28 (2 years ago)
Author:
taylorde
Message:

Tagging release 0.4... have fun folks

Location:
tdd-progress-bar/trunk
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • tdd-progress-bar/trunk

    • Property svn:ignore set to
      deploy.sh
      README.md
      .git
      .gitignore
  • tdd-progress-bar/trunk/inc/admin.php

    r499559 r523224  
    44* Array of color options 
    55*/ 
    6 $colors = array (  
     6$colors = array ( 
    77    'strawberry' => __ ( 'Strawberry', 'tdd_pb' ), 
    88    'fuchsia' => __( 'Fuchsia', 'tdd_pb' ), 
     
    1414    'yellow' => __( 'Yellow', 'tdd_pb' ), 
    1515    'orange' => __( 'Orange', 'tdd_pb' ), 
    16     'red'   => __( 'Red', 'tdd_pb' ), 
     16    'red' => __( 'Red', 'tdd_pb' ), 
    1717    'black' => __( 'Black', 'tdd_pb' ), 
    1818    'silver' => __( 'Silver', 'tdd_pb' ), 
    19     ); 
     19); 
    2020 
    2121/* 
     
    2727add_action( 'add_meta_boxes', 'tdd_pb_metabox_create' ); 
    2828 
    29 /* 
    30 * Post type meta box display 
    31 */ 
    32 function tdd_pb_metabox_display($post) { 
     29 
     30/** 
     31 * Meta box display for the Progress Bar post type. 
     32 * 
     33 * Provides the form controls necessary to select the color of the bar as well as: 
     34 * Percentage input 
     35 * X of Y input 
     36 * Label Display mode (only applicable if global show percentages option is on): 
     37 *  - None 
     38 *   - Percentage only 
     39 *   - Text label 
     40 *  - Percentage (text label) 
     41 *  - Text label (percentage) 
     42 */ 
     43function tdd_pb_metabox_display( $post ) { 
    3344    $tdd_pb_color = get_post_meta( $post->ID, '_tdd_pb_color', true ); 
    3445    $tdd_pb_percentage = get_post_meta( $post->ID, '_tdd_pb_percentage', true ); 
     46    $tdd_pb_input_method = get_post_meta( $post->ID, '_tdd_pb_input_method', true ); 
     47    $tdd_pb_start = get_post_meta( $post->ID, '_tdd_pb_start', true ); 
     48    $tdd_pb_end = get_post_meta( $post->ID, '_tdd_pb_end', true ); 
     49    $tdd_pb_percentage_display = get_post_meta( $post->ID, '_tdd_pb_percentage_display', true ); 
     50    $tdd_pb_xofy_display = get_post_meta( $post->ID, '_tdd_pb_xofy_display', true ); 
    3551?> 
    3652 
    3753    <table class="form-table"> 
    3854        <tr valign="top"> 
    39             <th scope="row"><label for="tdd_pb_color">Bar Color</label></th> 
     55            <th scope="row"><label for="tdd_pb_color"><?php _e( 'Bar Color', 'tdd_pb' ); ?></label></th> 
    4056            <td><select name="tdd_pb_color"> 
    4157                <?php global $colors; ?> 
    42                 <?php foreach ($colors as $color=>$label ): ?> 
     58                <?php foreach ( $colors as $color=>$label ): ?> 
    4359                    <option value="<?php echo $color; ?>" <?php selected( $tdd_pb_color, $color ); ?>"><?php echo $label; ?></option> 
    4460                <?php endforeach; ?> 
     
    4662        </tr> 
    4763        <tr valign="top"> 
    48             <th scope="row"><label for="tdd_pb_percentage">Percent Complete</label></th> 
    49             <td><input name="tdd_pb_percentage" type="text" maxlength="3" size="3" value="<?php echo esc_attr( $tdd_pb_percentage ); ?>">%</td> 
     64            <th scope="row"><?php _e( 'Calculation Mode', 'tdd_pb' ); ?></th> 
     65            <td> 
     66                <fieldset> 
     67                    <legend class="screen-reader-text"><span><?php _e( 'Input Method and Percentage Calculation', 'tdd_pb' ); ?></span></legend> 
     68 
     69                    <table class="form-table"> 
     70                        <tr valign="top"> 
     71                            <td> 
     72                                <label><input name="tdd_pb_input_method" type="radio" <?php checked( $tdd_pb_input_method, 'percentage' ); ?> value="percentage" > <?php _e( 'Percentage', 'tdd_pb' ); ?></label> 
     73                            </td> 
     74                            <td> 
     75                                <input name="tdd_pb_percentage" type="text" size="2" value="<?php echo esc_attr( $tdd_pb_percentage ); ?>"> %                           </td> 
     76                        </tr> 
     77                        <tr valign="top"> 
     78                            <td> 
     79                                <label><input name="tdd_pb_input_method" type="radio" <?php checked( $tdd_pb_input_method, 'xofy' ); ?> value="xofy" > <?php _e( 'Calculate Percentage (x of y)', 'tdd_pb' ); ?></label> 
     80                            </td> 
     81                            <td> 
     82                                <input name="tdd_pb_start" type="text" size="10" value="<?php echo esc_attr( $tdd_pb_start ); ?>"> <?php _e( 'of', 'tdd_pb' ); ?> 
     83                                <input name="tdd_pb_end" type="text" size="10" value="<?php echo esc_attr( $tdd_pb_end ); ?>"><br /> 
     84                                <span class="description"><?php _e( "Numbers only, don't include units", 'tdd_pb' ); ?></span> 
     85                            </td> 
     86                        </tr> 
     87                    </table> 
     88            </fieldset> 
     89            </td> 
     90        </tr> 
     91        <tr valign="top"> 
     92            <th scope="row"><?php _e( 'Display the following on the progress bar:', 'tdd_pb' ); ?></th> 
     93            <td> 
     94                <fieldset> 
     95                    <legend class="screen-reader-text"><span><?php _e( 'Display the following on the progress bar:', 'tdd_pb' ); ?></span></legend> 
     96                    <label><input name="tdd_pb_percentage_display" type="checkbox"  <?php checked( $tdd_pb_percentage_display, 'on' ); ?>> <?php _e( 'Display Calculated Percentage', 'tdd_pb' ); ?><label><br /> 
     97                    <label><input name="tdd_pb_xofy_display" type="checkbox" <?php checked( $tdd_pb_xofy_display, 'on' ); ?> > <?php _e( 'Display x of y Values', 'tdd_pb' ); ?></label> 
     98                </fieldset> 
     99            </td> 
    50100        </tr> 
    51101    </table> 
     102 
    52103    <?php $id = get_the_ID(); ?> 
    53     <p><?php _e( "Example shortcode: <code>[progress id={$id}]</code>", 'tdd_pb'); ?> </p> 
    54      
     104    <p><?php _e( "Example shortcode: <code>[progress id={$id}]</code>", 'tdd_pb' ); ?> </p> 
     105 
    55106    <?php echo tdd_pb_get_bars( array( 
    56         'ids' => array( get_the_ID() ), 
    57         'class' => 'tdd_pb_race', 
    58     ) ); 
    59     ?> 
    60      
     107            'ids' => array( get_the_ID() ), 
     108            'class' => 'tdd_pb_race', 
     109        ) ); 
     110?> 
     111 
    61112<?php 
    62113} 
    63114 
     115/** 
     116 * tdd_float_number_only 
     117 * Takes the input from a form field that expects a number, strips out everything except for numbers and decimals (.) 
     118 * Used for sanitation, not validation purposes 
     119 * @param string|int $str The input to filter. 
     120 * @return str The returned string 
     121 */ 
     122function tdd_float_number_only( $str ){ 
     123    $regexreturn = array(); 
     124    preg_match_all("/\.?[0-9]\.?/", $str, $regexreturn ); // Selects out just the numbers and any decimal places. 
     125    $regexreturn = implode( '', $regexreturn[0] ); // Organizes the regex array back into a string. 
     126    return $regexreturn; 
     127} 
     128 
    64129/* 
    65130* Saves the meta box info for the post 
    66131*/ 
    67 function tdd_pb_metabox_save( $post_id ){ 
    68     if ( isset( $_POST['tdd_pb_color'] ) ){ 
     132function tdd_pb_metabox_save( $post_id ) { 
     133    if ( isset( $_POST['tdd_pb_color'] ) ) { 
    69134        update_post_meta( $post_id, '_tdd_pb_color', strip_tags( $_POST['tdd_pb_color'] ) ); 
    70135    } 
    71      
    72     if ( isset( $_POST['tdd_pb_percentage'] ) ){ 
    73         //remove any percent signs ppl decided to put in 
    74         $percentage =  trim( $_POST['tdd_pb_percentage'], " %" ); 
    75         update_post_meta( $post_id, '_tdd_pb_percentage', strip_tags( $percentage ) ); 
    76     } 
    77      
     136 
     137    if ( isset( $_POST['tdd_pb_percentage'] ) ) { 
     138        $tdd_pb_percentage = tdd_float_number_only( $_POST['tdd_pb_percentage'] ); 
     139        update_post_meta( $post_id, '_tdd_pb_percentage', $tdd_pb_percentage ); 
     140    } 
     141 
     142    if ( isset( $_POST['tdd_pb_start'] ) ) { 
     143        $tdd_pb_start = tdd_float_number_only( $_POST['tdd_pb_start'] ); 
     144        update_post_meta( $post_id, '_tdd_pb_start', $tdd_pb_start ); 
     145    } 
     146 
     147    if ( isset( $_POST['tdd_pb_end'] ) ) { 
     148        $tdd_pb_end = tdd_float_number_only( $_POST['tdd_pb_end'] ); 
     149        update_post_meta( $post_id, '_tdd_pb_end', $tdd_pb_end ); 
     150    } 
     151 
     152    if ( isset( $_POST['tdd_pb_input_method'] ) ){ 
     153        update_post_meta( $post_id, '_tdd_pb_input_method', strip_tags( $_POST['tdd_pb_input_method'] ) ); 
     154    } 
     155 
     156    if ( isset( $_POST['tdd_pb_percentage_display'] ) ){ 
     157        update_post_meta( $post_id, '_tdd_pb_percentage_display', 'on' ); 
     158    } else { 
     159        update_post_meta( $post_id, '_tdd_pb_percentage_display', 'off' ); 
     160    } 
     161 
     162    if ( isset( $_POST['tdd_pb_xofy_display'] ) ){ 
     163        update_post_meta( $post_id, '_tdd_pb_xofy_display', 'on' ); 
     164    } else { 
     165        update_post_meta( $post_id, '_tdd_pb_xofy_display', 'off' ); 
     166    } 
     167 
     168    // $tdd_pb_input_method = get_post_meta( $post->ID, '_tdd_pb_input_method', true ); 
     169    // $tdd_pb_start = get_post_meta( $post->ID, '_tdd_pb_start', true ); 
     170    // $tdd_pb_end = get_post_meta( $post->ID, '_tdd_pb_end', true ); 
     171    // $tdd_pb_percentage_display = get_post_meta( $post->ID, '_tdd_pb_percentage_display', true ); 
     172    // $tdd_pb_xofy_display = get_post_meta( $post->ID, '_tdd_pb_xofy_display', true ); 
     173 
     174 
     175 
    78176} 
    79177add_action( 'save_post', 'tdd_pb_metabox_save' ); 
     
    82180* Adds custom columns to the Progress Bars view 
    83181*/ 
    84 function set_edit_tdd_pb_columns($columns) { 
    85     unset($columns['date']); 
    86     return array_merge($columns,  
    87               array('progress_bar' => 'Progress Bar', 
    88                     'shortcode' => 'Shortcode', 
    89                     'date' => __('Date'), 
    90                     )); 
    91 } 
    92 add_filter('manage_edit-tdd_pb_columns' , 'set_edit_tdd_pb_columns'); 
     182function set_edit_tdd_pb_columns( $columns ) { 
     183    unset( $columns['date'] ); 
     184    return array_merge( $columns, 
     185        array( 'progress_bar' => 'Progress Bar', 
     186            'shortcode' => 'Shortcode', 
     187            'date' => __( 'Date' ), 
     188        ) ); 
     189} 
     190add_filter( 'manage_edit-tdd_pb_columns' , 'set_edit_tdd_pb_columns' ); 
    93191 
    94192 
     
    96194* Put content in those custom columns 
    97195*/ 
    98 function tdd_pb_custom_columns( $column ){ 
     196function tdd_pb_custom_columns( $column ) { 
    99197    global $post; 
    100      
    101     switch ( $column ){ 
    102         case 'progress_bar': 
    103             echo tdd_pb_get_bars( array(  
     198 
     199    switch ( $column ) { 
     200    case 'progress_bar': 
     201        echo tdd_pb_get_bars( array( 
    104202                'ids' => array( $post->ID ), 
    105203                'class' => 'tdd_pb_race', 
    106204            ) ); 
    107205 
    108             break; 
    109         case 'shortcode': 
    110             echo '<code>[progress id='. $post->ID .']</code>'; 
    111             break; 
     206        break; 
     207    case 'shortcode': 
     208        echo '<code>[progress id='. $post->ID .']</code>'; 
     209        break; 
    112210    } 
    113211} 
     
    118216* Normally this would require a hook into save_posts (because it doesn't do it automatically), but we've already done that for the custom meta box info. 
    119217*/ 
    120 function tdd_pb_add_quick_edit( $column_name, $post_type ){ 
     218function tdd_pb_add_quick_edit( $column_name, $post_type ) { 
    121219    if ( $column_name != 'progress_bar' || $post_type != 'tdd_pb' ) return; 
    122     ?> 
    123      
     220?> 
     221 
    124222    <fieldset class="inline-edit-col-right"> 
    125223        <div class="inline-edit-col"> 
     
    132230                <select name="tdd_pb_color" id="tdd_pb_color"> 
    133231                <?php global $colors; ?> 
    134                 <?php foreach ($colors as $color=>$label ): ?> 
     232                <?php foreach ( $colors as $color=>$label ): ?> 
    135233                    <option value="<?php echo $color; ?>"><?php echo $label; ?></option> 
    136234                <?php endforeach; ?> 
     
    139237    </fieldset> 
    140238    <?php 
    141     } 
     239} 
    142240add_action( 'quick_edit_custom_box', 'tdd_pb_add_quick_edit', 20, 2 ); 
    143241 
     
    148246    global $wpdb; 
    149247 
    150     //If the incoming post id isn't numeric -- or isn't set, return an error.    
    151     if ( !is_numeric($_GET['post_id']) || !isset($_GET['post_id']) ){ 
     248    //If the incoming post id isn't numeric -- or isn't set, return an error. 
     249    if ( !is_numeric( $_GET['post_id'] ) || !isset( $_GET['post_id'] ) ) { 
    152250        $json = array ( 'error' => 'Post ID not set' ); 
    153         echo json_encode($json); 
     251        echo json_encode( $json ); 
    154252        die(); 
    155253    } 
    156254 
    157255    //Check for correct permissions, and verify nonce 
    158     if ( !current_user_can( 'edit_posts' ) || !check_ajax_referer( "tdd_pb_get_{$_GET['post_id']}", 'nonce', false) ) { 
     256    if ( !current_user_can( 'edit_posts' ) || !check_ajax_referer( "tdd_pb_get_{$_GET['post_id']}", 'nonce', false ) ) { 
    159257        $json = array ( 'error' => 'Permission Denied', 'GET' => $_GET ); 
    160         echo json_encode($json); 
     258        echo json_encode( $json ); 
    161259        die(); 
    162     }    
    163  
    164     $tdd_pb_percentage = get_post_meta( $_GET['post_id'], '_tdd_pb_percentage', true );  
     260    } 
     261 
     262    $tdd_pb_percentage = get_post_meta( $_GET['post_id'], '_tdd_pb_percentage', true ); 
    165263    $tdd_pb_color = get_post_meta( $_GET['post_id'], '_tdd_pb_color', true ); 
    166264 
     
    168266        'percentage' => $tdd_pb_percentage, 
    169267        'color' => $tdd_pb_color 
    170         ); 
    171  
    172     echo json_encode($json); 
     268    ); 
     269 
     270    echo json_encode( $json ); 
    173271    die(); 
    174272} 
     
    177275* Add some javascript to feed the correct values to the quick edit screen 
    178276*/ 
    179 function tdd_pb_quick_edit_js(){ 
     277function tdd_pb_quick_edit_js() { 
    180278    global $current_screen; 
    181     if ( ($current_screen->id != 'edit-tdd_pb') || ($current_screen->post_type != 'tdd_pb') ) return; 
    182     ?> 
     279    if ( ( $current_screen->id != 'edit-tdd_pb' ) || ( $current_screen->post_type != 'tdd_pb' ) ) return; 
     280?> 
    183281    <script type="text/javascript"> 
    184282        function set_inline_tdd_pb( post_id, nonce ){ 
    185283            inlineEditPost.revert(); //Calls an internal handler to make all the regular values fix themselves appropriately. 
    186              
     284 
    187285            var ajaxdata = { 
    188286                action: 'tdd_pb_get_custom_values', 
     
    190288                post_id: post_id 
    191289                } 
    192                  
     290 
    193291            jQuery.getJSON(ajaxurl, ajaxdata, function(response){ 
    194                  
     292 
    195293                //Set the percentage to be correct 
    196294                var tdd_pb_percentage = document.getElementById('tdd_pb_percentage'); 
    197295                tdd_pb_percentage.value = response.percentage; 
    198296 
    199                 //Set "selected" for the right option in the color select list               
     297                //Set "selected" for the right option in the color select list 
    200298                var tdd_pb_color = document.getElementById('tdd_pb_color'); 
    201299                jQuery('#tdd_pb_color').val(response.color).attr('selected', true); 
    202300            }); 
    203              
     301 
    204302        } //end set_inline_tdd_pb 
    205303    </script> 
     
    211309* Binds the tdd_pb_quick_edit_js to the quick edit button 
    212310*/ 
    213 function tdd_pb_quick_edit_button( $actions, $post ){ 
     311function tdd_pb_quick_edit_button( $actions, $post ) { 
    214312    global $current_screen; 
    215     if ( ($current_screen->id != 'edit-tdd_pb') || ($current_screen->post_type != 'tdd_pb') ) return $actions; 
    216      
     313    if ( ( $current_screen->id != 'edit-tdd_pb' ) || ( $current_screen->post_type != 'tdd_pb' ) ) return $actions; 
     314 
    217315    $nonce = wp_create_nonce( "tdd_pb_get_{$post->ID}" ); 
    218          
     316 
    219317    $actions['inline hide-if-no-js'] = '<a href="#" class="editinline" title="'; 
    220     $actions['inline hide-if-no-js'] .= esc_attr( __('Edit this item inline') ). '" '; 
     318    $actions['inline hide-if-no-js'] .= esc_attr( __( 'Edit this item inline' ) ). '" '; 
    221319    $actions['inline hide-if-no-js'] .= ' onclick="set_inline_tdd_pb('.$post->ID.', \''.$nonce.'\');">'; 
    222     $actions['inline hide-if-no-js'] .= __('Quick&nbsp;Edit'); 
     320    $actions['inline hide-if-no-js'] .= __( 'Quick&nbsp;Edit' ); 
    223321    $actions['inline hide-if-no-js'] .= '</a>'; 
    224322    return $actions; 
     
    230328* View Settings admin page 
    231329*/ 
    232 function tdd_pb_view_settings(){ 
    233 $tdd_pb_options = get_option( 'tdd_pb_options'); 
     330function tdd_pb_view_settings() { 
     331    $tdd_pb_options = get_option( 'tdd_pb_options' ); 
    234332 
    235333?> 
     
    237335    <?php screen_icon( 'plugins' ); ?> 
    238336    <h2><?php _e( 'TDD Progress Bars', 'tdd_pb' ); ?></h2> 
    239      
     337 
    240338    <form action="options.php" method="post"> 
    241339    <?php settings_fields( 'tdd_pb_options' ); ?> 
     
    250348function tdd_pb_admin_init() { 
    251349    register_setting( 'tdd_pb_options', 'tdd_pb_options', 'tdd_pb_options_validate' ); 
    252      
     350 
    253351    //register Scripts and Styles section & controls 
    254352    add_settings_section( 'tdd_pb_sas', __( 'Scripts and Styles', 'tdd_pb' ), 'tdd_pb_admin_sasheader', __FILE__ ); 
    255353    add_settings_field( 'animate', __( 'Animate Bars', 'tdd_pb' ), 'tdd_pb_admin_form_animate', __FILE__ , 'tdd_pb_sas' ); 
    256     add_settings_field( 'default_css', __( 'Use Default CSS', 'tdd_pb' ), 'tdd_pb_admin_form_default_css', __FILE__, 'tdd_pb_sas'); 
     354    add_settings_field( 'default_css', __( 'Use Default CSS', 'tdd_pb' ), 'tdd_pb_admin_form_default_css', __FILE__, 'tdd_pb_sas' ); 
    257355 
    258356    //register Percent section & controls 
    259357    add_settings_section( 'tdd_pb_percent', __( 'Percentage Displays', 'tdd_pb' ), 'tdd_pb_admin_percentheader', __FILE__ ); 
    260     add_settings_field( 'display_percentage', __( 'Display Percent Complete', 'tdd_pb' ), 'tdd_pb_admin_form_perecent_display', __FILE__, 'tdd_pb_percent' ); 
     358    add_settings_field( 'display_percentage', __( 'Display Text on the Bar', 'tdd_pb' ), 'tdd_pb_admin_form_perecent_display', __FILE__, 'tdd_pb_percent' ); 
    261359    add_settings_field( 'percentage_color', __( 'Color of Percentage Text', 'tdd_pb' ), 'tdd_pb_admin_form_percentage_color', __FILE__, 'tdd_pb_percent' ); 
    262360    add_settings_field( 'bar_background_color', __( 'Color of Bar Background', 'tdd_pb' ), 'tdd_pb_admin_form_bar_background_color', __FILE__, 'tdd_pb_percent' ); 
     
    266364 
    267365//Scripts & Styles section header 
    268 function tdd_pb_admin_sasheader(){ 
     366function tdd_pb_admin_sasheader() { 
    269367    _e( "<p>The following two boxes allow you to stop including the animation javascript and the default CSS on each page load. It's highly suggested that you don't turn off the Default CSS option unless you have a replacement in mind. The Animate Bars option can be turned off freely if you'd prefer the bars didn't have that cool animation (or you want to save HTTP requests).</p>", 'tdd_pb' ); 
    270368} 
    271369 
    272370//Animate Checkbox 
    273 function tdd_pb_admin_form_animate(){ 
    274     $options = get_option('tdd_pb_options'); 
    275     $checked = ($options['animate']) ? ' checked="checked" ' : ''; 
     371function tdd_pb_admin_form_animate() { 
     372    $options = get_option( 'tdd_pb_options' ); 
     373    $checked = ( $options['animate'] ) ? ' checked="checked" ' : ''; 
    276374    echo "<input name='tdd_pb_options[animate]' id='animate' type='checkbox' ". $checked ."> <br /> "; 
    277375    _e( "<small>This script depends on jQuery, so it will ensure that is loaded as well</small>", 'tdd_pb' ); 
     
    279377 
    280378//Default CSS 
    281 function tdd_pb_admin_form_default_css(){ 
    282     $options = get_option('tdd_pb_options'); 
    283     $checked = ($options['default_css']) ? ' checked="checked" ' : ''; 
     379function tdd_pb_admin_form_default_css() { 
     380    $options = get_option( 'tdd_pb_options' ); 
     381    $checked = ( $options['default_css'] ) ? ' checked="checked" ' : ''; 
    284382    echo "<input name='tdd_pb_options[default_css]' id='default_css' type='checkbox' ".$checked.">"; 
    285383} 
     
    287385 
    288386//Percentage displays section header 
    289 function tdd_pb_admin_percentheader(){ 
    290     _e( "<p>By default, the percentage progress is displayed in the bar. This allows you to optionally turn that off and/or set the color of the text</p>", 'tdd_pb' ); 
     387function tdd_pb_admin_percentheader() { 
     388    _e( "<p>This is a global control to turn on and off text being displayed on the bar. Individual bars may show the percentage, text (x of y), both, or nothing if this box is checked. Bars will show nothing if this box is unchecked.</p>", 'tdd_pb' ); 
    291389} 
    292390 
    293391 
    294392//Percent Display 
    295 function tdd_pb_admin_form_perecent_display(){ 
    296     $options = get_option('tdd_pb_options'); 
    297     $checked = ($options['display_percentage']) ? ' checked="checked" ' : ''; 
     393function tdd_pb_admin_form_perecent_display() { 
     394    $options = get_option( 'tdd_pb_options' ); 
     395    $checked = ( $options['display_percentage'] ) ? ' checked="checked" ' : ''; 
    298396    echo "<input name='tdd_pb_options[display_percentage]' id='display_percentage' type='checkbox' ". $checked .">"; 
    299397} 
    300398 
    301399//percentage_color 
    302 function tdd_pb_admin_form_percentage_color(){ 
    303     $options = get_option('tdd_pb_options'); 
     400function tdd_pb_admin_form_percentage_color() { 
     401    $options = get_option( 'tdd_pb_options' ); 
    304402    _e( "#<input name='tdd_pb_options[percentage_color]' id='percentage_color' type='text' value='{$options['percentage_color']}' maxlength='6' size='6' />", 'tdd_pb' ); 
    305403} 
    306404 
    307 function tdd_pb_admin_form_bar_background_color(){ 
    308     $options = get_option('tdd_pb_options'); 
     405function tdd_pb_admin_form_bar_background_color() { 
     406    $options = get_option( 'tdd_pb_options' ); 
    309407    echo "#<input name='tdd_pb_options[bar_background_color]' id='bar_backround_color' type='text' value='{$options['bar_background_color']}' maxlength='6' size='6' />"; 
    310408} 
    311409 
    312410//validate 
    313 function tdd_pb_options_validate( $input ){ 
    314      
    315         //whitelist checkboxes (add them back in, even if false) 
    316         $input['display_percentage'] =  ( isset( $input['display_percentage'] ) ) ? $input['display_percentage'] : false; 
    317         $input['animate'] =  ( isset( $input['animate'] ) ) ? $input['animate'] : false; 
    318         $input['default_css'] =  ( isset( $input['default_css'] ) ) ? $input['default_css'] : false; 
    319      
     411function tdd_pb_options_validate( $input ) { 
     412 
     413    //whitelist checkboxes (add them back in, even if false) 
     414    $input['display_percentage'] =  ( isset( $input['display_percentage'] ) ) ? $input['display_percentage'] : false; 
     415    $input['animate'] =  ( isset( $input['animate'] ) ) ? $input['animate'] : false; 
     416    $input['default_css'] =  ( isset( $input['default_css'] ) ) ? $input['default_css'] : false; 
     417 
    320418    return $input; 
    321419} 
  • tdd-progress-bar/trunk/readme.txt

    r499602 r523224  
    22Contributors: taylorde 
    33Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=FEQG5KTTPRRXS 
    4 Tags: progress, shortcode 
    5 Requires at least: 3.2.1 
     4Tags: progress, shortcode, widget 
     5Requires at least: 3.3 
    66Tested up to: 3.3.1 
    7 Stable tag: 0.3.5 
     7Stable tag: 0.4 
    88 
    9 Configure and display any number of percent-complete progress bars. 
     9Configure and display any number of percent-complete progress bars.8 
    1010 
    1111== Description == 
     
    17172. Progress Bar management page showing all the colors available 
    18183. A solo Progress Bar 
     194. Bar Options 
    1920 
    2021Unfortunately screenshots don't really capture how cool these look while animating... 
     
    2425= It doesn't look right.. = 
    2526This project uses some cutting-edge CSS3 to make things look cooler like drop shadow, inner-shadow, border-radius, etc. If it doesn't look right in your browser first, consider upgrading, second: let me know what browser you're using to see if I want to consider support. Things should degrade gracefully for non-cutting edge browsers (although IE6 is still going to look like crap no matter what you do). You're welcome to write your own CSS to override what I've already written (or un-check "Default Styles" on the settings page and roll-yer-own). 
     27 
     28= How do I use the filter hook to modify a percentage? = 
     29Add this to your functions.php file, or your own plugin. 
     30`   <?php 
     31        add_filter( 'tdd_pb_calculated_percentage', 'change_percentage', 10, 2 ); 
     32        function change_percentage($percentage, $id){ 
     33            //Only apply to post (bar) ID 120, if it isn't 120, just return 
     34            if ($id != 120) 
     35                return $percentage; 
     36 
     37            $newpercentage = $percentage + 10; // add 10% for effort. 
     38            return $newpercentage; 
     39        } 
     40    ?> 
     41` 
     42You can use this to add 10%, like the example above, or do something cool like pull in data from an external API. If you come up with something fun and clever, I'd love to feature it! 
    2643 
    2744== Installation == 
     
    4461 
    4562== Changelog == 
     63 
     64= 0.4 = 
     65* Progress bars can now be defined using a percentage or two numbers ( x of y ) and let the plugin do the calculation 
     66* The text display on the bar itself can be nothing, the percentage, the two numbers, or both. The global setting to turn this on and off still exists. 
     67* Changed the checkbox on the admin page to make it clear it is a global "off" switch for bar text, not just percentage. 
     68* Added a filter hook for the percentage being shown. This provides the ability to hook in your own method of calculating percentages. The hook name is `tdd_pb_calculated_percentage` 
    4669 
    4770= 0.3.5 = 
  • tdd-progress-bar/trunk/tdd-progress-bar.php

    r499602 r523224  
    44Plugin URI: http://github.com/tddewey/tdd-progress 
    55Description: Manage and display progress bars 
    6 Version: 0.3.5 
     6Version: 0.4 
    77Author: Taylor D. Dewey 
    88Author URI: http://websitesthatdontsuck.com 
     
    1717            - display percentage - default=true 
    1818            - percentage color - default=#ececec; 
    19          
     19 
    2020        shortcode options: 
    2121            - race height (if multiple ID's involved) 
    2222            - width 
    23          
     23 
    2424        bar specific options: 
    2525            - color/graphic 
    2626            - percentage (or API call) 
    27              
     27 
    2828 
    2929        @todo: 
    3030            make a variety of the colored bars. Assemble into a sprite and work-in above. Only need the width to be long enough to feel random. Blend the seam. 
    31              
     31 
    3232            Global options page 
    33              
     33 
    3434            Page to add progress bars. 
    3535                - Name 
    3636                - Bar style 
    3737                - Perecentage / or API call. 
    38                  
     38 
    3939*/ 
    4040 
     
    6262        'percentage_color' => 'ececec', 
    6363    ); 
    64      
     64 
    6565    update_option( 'tdd_pb_options', $tdd_pb_options ); 
    6666} 
     
    126126        'not_found_in_trash' => __( 'No Progress Bars Found in the Trash', 'tdd_pb' ), 
    127127    ); 
    128      
     128 
    129129    $args = array( 
    130130        'labels' => $labels, 
     
    140140add_action( 'init', 'tdd_pb_register_post_type' ); 
    141141 
    142 /*  
     142/* 
    143143* Set up admin menus 
    144144*/ 
     
    178178        'class' => '', 
    179179        ), $args ); 
    180      
    181      
     180 
     181 
    182182    //explode "id" and "ids" on their commas separately, then merge the arrays together 
    183183    $idarr = explode( ',', $args['id'] ); 
    184184    $idsarr = explode( ',', $args['ids'] ); 
    185185    $idsarr = array_merge($idarr, $idsarr); 
    186      
     186 
    187187    //Request some bars 
    188188    $return = tdd_pb_get_bars(array( 
     
    191191        'class' => $args['class'], 
    192192    )); 
    193      
     193 
    194194    //Return them bars 
    195195    return $return; 
     
    218218    $tdd_pb_options = get_option( 'tdd_pb_options'); 
    219219 
    220      
    221220    //parse incoming arguments against default. 
    222221    $args = wp_parse_args( $args, $defaults ); 
    223222 
    224  
    225223    //Filter the array to ensure we're getting things that look like integers. Will also filter out blank array items (i.e. '' ) 
    226224    $idsarr = array_filter( $args['ids'], 'is_numeric' ); 
     
    231229    //Set up our global container 
    232230    $return = '<div class="tdd_pb_global_container '.$race.' '.$args['class'].'" style="width:'.strip_tags( $args['width'] ).'">'; 
    233      
     231 
    234232    //If there are no ids to display, this is kind of a moot proccess - so let's say so: 
    235233    if ( count( $idsarr ) <= 0 ){ 
     
    237235        return $return; 
    238236    } 
    239      
     237 
    240238    //Setup a new WP_Query for our progress bars. 
    241239    $tdd_pb_query = new WP_Query(); 
     
    244242        'posts_per_page' => -1, 
    245243        'post__in' => $idsarr, 
    246         'meta_key' => '_tdd_pb_percentage' 
     244        'no_found_rows' => true, 
     245//      'meta_key' => '_tdd_pb_percentage' //Used to be this was the only, and required key. Is no longer the case... 
    247246    )); 
    248247 
     
    252251        return $return; 
    253252        } 
    254      
     253 
    255254    while ( $tdd_pb_query->have_posts() ): $tdd_pb_query->the_post(); 
    256255        $percentage = strip_tags( get_post_meta( get_the_ID(), '_tdd_pb_percentage', true ) ); 
     256        $start = strip_tags( get_post_meta( get_the_ID(), '_tdd_pb_start', true ) ); 
     257        $end = strip_tags( get_post_meta( get_the_ID(), '_tdd_pb_end', true ) ); 
     258        $input_method = strip_tags( get_post_meta( get_the_ID(), '_tdd_pb_input_method', true ) ); 
     259        $percentage_display = strip_tags( get_post_meta( get_the_ID(), '_tdd_pb_percentage_display', true ) ); 
     260        $xofy_display = strip_tags( get_post_meta( get_the_ID(), '_tdd_pb_xofy_display', true ) ); 
     261 
     262        if ( $input_method == 'xofy' ){ 
     263            $calcpercentage = round( ($start/$end)*100, 2 ); 
     264        } else { 
     265            $calcpercentage = $percentage; 
     266        } 
     267 
     268        //This filter allows you to hook in and modify the percentage, perhaps based on a fancy API call... 
     269        $calcpercentage = apply_filters( 'tdd_pb_calculated_percentage', $calcpercentage, get_the_ID() ); 
     270 
    257271        $color = strip_tags( get_post_meta( get_the_ID(), '_tdd_pb_color', true ) ); 
    258272        //if no color, define a default 
    259273        $color = (!$color) ? $args['default_color'] : 'tdd_pb_'.$color; 
    260         $return .= '<div title="'.get_the_title() .': '.$percentage.'%" class="tdd_pb_bar_container" style="background-color: #'. $tdd_pb_options["bar_background_color"] .'" role="progressbar" aria-valuenow="'.$percentage.'" aria-valuemax="100" aria-valuemin="0">'; 
    261         if ($tdd_pb_options['display_percentage']){ 
    262             $return .= '<div class="tdd_pb_numbers" style="color: #'.$tdd_pb_options["percentage_color"].'">'. $percentage .'%</div>'; 
    263         } 
    264         $return .= '<div class="tdd_pb_bar '. $color .'" style="width:'. $percentage .'%"></div></div>'; 
    265      
     274        $return .= '<div title="'.get_the_title() .': '.$calcpercentage.'%" class="tdd_pb_bar_container" style="background-color: #'. $tdd_pb_options["bar_background_color"] .'" role="progressbar" aria-valuenow="'.$calcpercentage.'" aria-valuemax="100" aria-valuemin="0">'; 
     275        if ($tdd_pb_options['display_percentage']): 
     276            $return .= '<div class="tdd_pb_numbers" style="color: #'.$tdd_pb_options["percentage_color"].'">'; 
     277 
     278            if ( $percentage_display == 'on' || $percentage_display === '' ){ 
     279                $return .= $calcpercentage .'%'; 
     280            } 
     281 
     282            if ( $xofy_display == 'on' ){ 
     283                $return .='&nbsp;&nbsp;' . $start . ' ' . __( 'of', 'tdd_pb' ) . ' ' . $end; 
     284            } 
     285 
     286            $return .='</div>'; 
     287        endif; 
     288        $return .= '<div class="tdd_pb_bar '. $color .'" style="width:'. $calcpercentage .'%"></div></div>'; 
     289 
    266290    endwhile; 
    267291 
Note: See TracChangeset for help on using the changeset viewer.