Changeset 549997
- Timestamp:
- 05/28/2012 08:38:05 PM (12 years ago)
- Location:
- tdd-progress-bar/trunk
- Files:
-
- 36 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
tdd-progress-bar/trunk/css/default.css
r499559 r549997 1 .tdd_pb_global_container {2 max-width: 900px;3 width: 400px;4 }5 6 1 .tdd_pb_bar_container { 7 2 position: relative; 8 3 background-color: #333; 9 4 overflow: hidden; 5 10 6 height: 50px; 11 border: 1px solid black;12 7 13 8 -webkit-box-shadow: inset 0 0 4px #000000; … … 19 14 20 15 .tdd_pb_red { 21 background-position: 0px 0; 22 } 23 24 .tdd_pb_race .tdd_pb_red { 25 background-position: 0px -12px; 16 background-color: #ec0d0d; 26 17 } 27 18 28 19 .tdd_pb_orange { 29 background-position: 0px -50px; 30 } 31 32 .tdd_pb_race .tdd_pb_orange { 33 background-position: 0px -62px; 20 background-color: #e67200; 34 21 } 35 22 36 23 .tdd_pb_yellow { 37 background-position: 0px -100px; 38 } 39 40 .tdd_pb_race .tdd_pb_yellow { 41 background-position: 0px -112px; 24 background-color: #d6e418; 42 25 } 43 26 44 27 .tdd_pb_green { 45 background-position: 0px -150px; 46 } 47 48 .tdd_pb_race .tdd_pb_green { 49 background-position: 0px -162px; 28 background-color: #7cd824; 50 29 } 51 30 52 31 .tdd_pb_teal { 53 background-position: 0px -200px; 54 } 55 56 .tdd_pb_race .tdd_pb_teal { 57 background-position: 0px -212px; 32 background-color: #28d575; 58 33 } 59 34 60 35 .tdd_pb_lightblue { 61 background-position: 0px -250px; 62 } 63 64 .tdd_pb_race .tdd_pb_lightblue { 65 background-position: 0px -262px; 36 background-color: #2eb0b1; 66 37 } 67 38 68 39 .tdd_pb_blue { 69 background-position: 0px -300px; 70 } 71 72 .tdd_pb_race .tdd_pb_blue { 73 background-position: 0px -312px; 40 background-color: #003486; 74 41 } 75 42 76 43 .tdd_pb_purple { 77 background-position: 0px -350px; 78 } 79 80 .tdd_pb_race .tdd_pb_purple { 81 background-position: 0px -362px; 44 background-color: #7400e9; 82 45 } 83 46 84 47 .tdd_pb_fuchsia { 85 background-position: 0px -400px; 86 } 87 88 .tdd_pb_race .tdd_pb_fuchsia { 89 background-position: 0px -415px; 48 background-color: #aa00a9; 90 49 } 91 50 92 51 .tdd_pb_strawberry { 93 background-position: 0px -450px; 94 } 95 96 .tdd_pb_race .tdd_pb_strawberry { 97 background-position: 0px -465px; 52 background-color: #980041; 98 53 } 99 54 100 55 .tdd_pb_black { 101 background-position: 0px -500px; 102 } 103 104 .tdd_pb_race .tdd_pb_black { 105 background-position: 0px -515px; 56 background-color: #121212; 106 57 } 107 58 108 59 .tdd_pb_silver { 109 background-position: 0px -550px; 110 } 111 112 .tdd_pb_race .tdd_pb_silver { 113 background-position: 0px -565px; 60 background-color: #c0c0c0; 114 61 } 115 62 116 63 .tdd_pb_bar { 117 background-image: url(../images/bars .png);64 background-image: url(../images/bars.png); 118 65 width: 0; 119 66 height: 100%; 67 120 68 121 69 -webkit-box-shadow: 1px 0 4px #000; 122 70 -moz-box-shadow: 1px 0 4px #000; 123 71 box-shadow: 1px 0 4px #000; 124 z-index: 2; 72 z-index: 1; 73 border-top-right-radius: 15px 100px; 74 border-bottom-right-radius: 15px 100px; 75 overflow: hidden; 76 } 77 78 /* Applies a "shine" effect */ 79 .tdd_pb_bar:before { 80 content: ' '; 81 position: absolute; 82 height: 100%; 83 width: 100%; 84 85 background: -webkit-linear-gradient(top, rgba(255,255,255,0.5) 0%, rgba(255,255,255,0) 100%); 86 background: -moz-linear-gradient(top, rgba(255,255,255,0.5) 0%, rgba(255,255,255,0) 100%); 87 background: -o-linear-gradient(top, rgba(255,255,255,0.5) 0%, rgba(255,255,255,0) 100%); 88 background: -ms-linear-gradient(top, rgba(255,255,255,0.5) 0%, rgba(255,255,255,0) 100%); 89 background: linear-gradient(top, rgba(255,255,255,0.5) 0%, rgba(255,255,255,0) 100%); /* W3C */ 90 -image filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#80ffffff', endColorstr='#00ffffff',GradientType=0 ); /* IE6-9 */ 91 125 92 border-top-right-radius: 15px 100px; 126 93 border-bottom-right-radius: 15px 100px; … … 139 106 text-shadow: -1px -1px 1px #000; 140 107 font-size: 30px; 141 margin-top: 7px; 142 margin-right: 10px; 108 margin: 7px 10px 0; 143 109 color: #ececec; 144 110 position: absolute; 145 111 right: 0; 146 112 line-height: 1em; 113 147 114 } -
tdd-progress-bar/trunk/css/default.min.css
r499602 r549997 1 .tdd_pb_ global_container{max-width:900px;width:400px;}.tdd_pb_bar_container{position:relative;background-color:#333;overflow:hidden;height:50px;border:1px solid black;-webkit-box-shadow:inset 0 0 4px #000000;-moz-box-shadow:inset 0 0 4px #000000;box-shadow:inset 0 0 4px #000000;border-top-right-radius:15px 100px;border-bottom-right-radius:15px 100px;}.tdd_pb_red{background-position:0px 0;}.tdd_pb_race .tdd_pb_red{background-position:0px -12px;}.tdd_pb_orange{background-position:0px -50px;}.tdd_pb_race .tdd_pb_orange{background-position:0px -62px;}.tdd_pb_yellow{background-position:0px -100px;}.tdd_pb_race .tdd_pb_yellow{background-position:0px -112px;}.tdd_pb_green{background-position:0px -150px;}.tdd_pb_race .tdd_pb_green{background-position:0px -162px;}.tdd_pb_teal{background-position:0px -200px;}.tdd_pb_race .tdd_pb_teal{background-position:0px -212px;}.tdd_pb_lightblue{background-position:0px -250px;}.tdd_pb_race .tdd_pb_lightblue{background-position:0px -262px;}.tdd_pb_blue{background-position:0px -300px;}.tdd_pb_race .tdd_pb_blue{background-position:0px -312px;}.tdd_pb_purple{background-position:0px -350px;}.tdd_pb_race .tdd_pb_purple{background-position:0px -362px;}.tdd_pb_fuchsia{background-position:0px -400px;}.tdd_pb_race .tdd_pb_fuchsia{background-position:0px -415px;}.tdd_pb_strawberry{background-position:0px -450px;}.tdd_pb_race .tdd_pb_strawberry{background-position:0px -465px;}.tdd_pb_black{background-position:0px -500px;}.tdd_pb_race .tdd_pb_black{background-position:0px -515px;}.tdd_pb_silver{background-position:0px -550px;}.tdd_pb_race .tdd_pb_silver{background-position:0px -565px;}.tdd_pb_bar{background-image:url(../images/bars.png);width:0;height:100%;-webkit-box-shadow:1px 0 4px #000;-moz-box-shadow:1px 0 4px #000;box-shadow:1px 0 4px #000;z-index:2;border-top-right-radius:15px 100px;border-bottom-right-radius:15px 100px;}.tdd_pb_race .tdd_pb_bar_container{height:25px;}.tdd_pb_race .tdd_pb_bar_container .tdd_pb_numbers{font-size:15px;margin-top:4px;}.tdd_pb_numbers{text-shadow:-1px -1px 1px #000;font-size:30px;margin-top:7px;margin-right:10px;color:#ececec;position:absolute;right:0;line-height:1em;}1 .tdd_pb_;} -
tdd-progress-bar/trunk/inc/admin.php
r523224 r549997 27 27 add_action( 'add_meta_boxes', 'tdd_pb_metabox_create' ); 28 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 29 49 30 50 /** … … 42 62 */ 43 63 function tdd_pb_metabox_display( $post ) { 64 65 44 66 $tdd_pb_color = get_post_meta( $post->ID, '_tdd_pb_color', true ); 45 $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 ); 67 68 if ( $input_method = get_post_meta( $post->ID, '_tdd_pb_input_method', true ) ){ 69 $whitelist = array( 'percentage', 'xofy' ); 70 if ( in_array( $input_method, $whitelist ) ) 71 $tdd_pb_input_method = $input_method; 72 else 73 $tdd_pb_input_method = 'percentage'; 74 } else { 75 $tdd_pb_input_method = 'percentage'; 76 } 77 78 $tdd_pb_percentage = absint( get_post_meta( $post->ID, '_tdd_pb_percentage', true ) ); 79 $tdd_pb_custom_color = tdd_pb_sanitize_color_hex_raw( get_post_meta( $post->ID, '_tdd_pb_custom_color', true ) ); 80 $tdd_pb_start = intval( get_post_meta( $post->ID, '_tdd_pb_start', true ) ); 81 $tdd_pb_end = intval( get_post_meta( $post->ID, '_tdd_pb_end', true ) ); 82 83 if ( $percentage_display = get_post_meta( $post->ID, '_tdd_pb_percentage_display', true ) ){ 84 $whitelist = array( 'on', 'off' ); 85 if ( in_array( $percentage_display, $whitelist ) ) 86 $tdd_pb_percentage_display = $percentage_display; 87 else 88 $tdd_pb_percentage_display = 'on'; 89 } else { 90 $tdd_pb_percentage_display = 'on'; 91 } 92 93 if ( $xofy_display = get_post_meta( $post->ID, '_tdd_pb_xofy_display', true ) ){ 94 $whitelist = array( 'on', 'off' ); 95 if ( in_array( $xofy_display, $whitelist ) ) 96 $tdd_pb_xofy_display = $xofy_display; 97 else 98 $tdd_pb_xofy_display = 'off'; 99 } else { 100 $tdd_pb_xofy_display = 'off'; 101 } 102 51 103 ?> 52 104 … … 56 108 <td><select name="tdd_pb_color"> 57 109 <?php global $colors; ?> 110 58 111 <?php foreach ( $colors as $color=>$label ): ?> 59 <option value="<?php echo $color; ?>" <?php selected( $tdd_pb_color, $color ); ?> "><?php echo $label; ?></option>112 <option value="<?php echo $color; ?>" <?php selected( $tdd_pb_color, $color ); ?>><?php echo $label; ?></option> 60 113 <?php endforeach; ?> 61 </select></td> 114 </select> 115 116 <label for="tdd_pb_custom_color">or custom: </label> 117 <input type="text" class="color" name="tdd_pb_custom_color" id="tdd_pb_custom_color" size="6" value="<?php echo $tdd_pb_custom_color; ?>"> 118 </td> 62 119 </tr> 63 120 <tr valign="top"> … … 107 164 'ids' => array( get_the_ID() ), 108 165 'class' => 'tdd_pb_race', 166 109 167 ) ); 168 110 169 ?> 111 170 … … 113 172 } 114 173 115 /**116 * tdd_float_number_only117 * 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 purposes119 * @param string|int $str The input to filter.120 * @return str The returned string121 */122 function 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 129 174 /* 130 175 * Saves the meta box info for the post 131 176 */ 132 177 function tdd_pb_metabox_save( $post_id ) { 133 if ( isset( $_POST['tdd_pb_color'] ) ) { 134 update_post_meta( $post_id, '_tdd_pb_color', strip_tags( $_POST['tdd_pb_color'] ) ); 135 } 178 179 if ( isset( $_POST['tdd_pb_color'] ) ) 180 update_post_meta( $post_id, '_tdd_pb_color', sanitize_html_class( $_POST['tdd_pb_color'] ) ); 181 182 if ( isset( $_POST['tdd_pb_custom_color'] ) ) 183 update_post_meta( $post_id, '_tdd_pb_custom_color', tdd_pb_sanitize_color_hex_raw( $_POST['tdd_pb_custom_color'] ) ); 184 else 185 delete_post_meta( $post_id, '_tdd_pb_custom_color' ); 136 186 137 187 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 ); 188 update_post_meta( $post_id, '_tdd_pb_percentage', absint( $_POST['tdd_pb_percentage'] ) ); 140 189 } 141 190 142 191 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 ); 192 update_post_meta( $post_id, '_tdd_pb_start', intval( $_POST['tdd_pb_start'] ) ); 145 193 } 146 194 147 195 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 ); 196 update_post_meta( $post_id, '_tdd_pb_end', intval( $_POST['tdd_pb_end'] ) ); 150 197 } 151 198 152 199 if ( isset( $_POST['tdd_pb_input_method'] ) ){ 153 update_post_meta( $post_id, '_tdd_pb_input_method', strip_tags( $_POST['tdd_pb_input_method'] ) ); 200 switch ( $_POST['tdd_pb_input_method'] ){ 201 case 'xofy': 202 update_post_meta( $post_id, '_tdd_pb_input_method', 'xofy' ); 203 break; 204 default: 205 update_post_meta( $post_id, '_tdd_pb_input_method', 'percentage' ); 206 } 154 207 } 155 208 … … 165 218 update_post_meta( $post_id, '_tdd_pb_xofy_display', 'off' ); 166 219 } 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 220 176 221 } … … 202 247 'ids' => array( $post->ID ), 203 248 'class' => 'tdd_pb_race', 249 204 250 ) ); 205 251 … … 229 275 <label class="alignright"><span class="title"><?php _e( 'Bar Color', 'tdd_pb' ); ?></span> 230 276 <select name="tdd_pb_color" id="tdd_pb_color"> 277 231 278 <?php global $colors; ?> 232 279 <?php foreach ( $colors as $color=>$label ): ?> … … 324 371 add_filter( 'post_row_actions', 'tdd_pb_quick_edit_button', 10, 2 ); 325 372 326 327 /* 328 * View Settings admin page 329 */ 330 function tdd_pb_view_settings() { 331 $tdd_pb_options = get_option( 'tdd_pb_options' ); 332 333 ?> 334 <div class="wrap"> 335 <?php screen_icon( 'plugins' ); ?> 336 <h2><?php _e( 'TDD Progress Bars', 'tdd_pb' ); ?></h2> 337 338 <form action="options.php" method="post"> 339 <?php settings_fields( 'tdd_pb_options' ); ?> 340 <?php do_settings_sections( __FILE__ ); ?> 341 <input name="Submit" type="submit" value="<?php _e( 'Save Changes', 'tdd_pb' ); ?>" class="button-primary" /> 342 </form> 343 </div> 344 <?php 345 } 346 347 //Register settings 348 function tdd_pb_admin_init() { 349 register_setting( 'tdd_pb_options', 'tdd_pb_options', 'tdd_pb_options_validate' ); 350 351 //register Scripts and Styles section & controls 352 add_settings_section( 'tdd_pb_sas', __( 'Scripts and Styles', 'tdd_pb' ), 'tdd_pb_admin_sasheader', __FILE__ ); 353 add_settings_field( 'animate', __( 'Animate Bars', 'tdd_pb' ), 'tdd_pb_admin_form_animate', __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' ); 355 356 //register Percent section & controls 357 add_settings_section( 'tdd_pb_percent', __( 'Percentage Displays', 'tdd_pb' ), 'tdd_pb_admin_percentheader', __FILE__ ); 358 add_settings_field( 'display_percentage', __( 'Display Text on the Bar', 'tdd_pb' ), 'tdd_pb_admin_form_perecent_display', __FILE__, 'tdd_pb_percent' ); 359 add_settings_field( 'percentage_color', __( 'Color of Percentage Text', 'tdd_pb' ), 'tdd_pb_admin_form_percentage_color', __FILE__, 'tdd_pb_percent' ); 360 add_settings_field( 'bar_background_color', __( 'Color of Bar Background', 'tdd_pb' ), 'tdd_pb_admin_form_bar_background_color', __FILE__, 'tdd_pb_percent' ); 361 362 } 363 add_action( 'admin_init', 'tdd_pb_admin_init' ); 364 365 //Scripts & Styles section header 366 function tdd_pb_admin_sasheader() { 367 _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' ); 368 } 369 370 //Animate Checkbox 371 function tdd_pb_admin_form_animate() { 372 $options = get_option( 'tdd_pb_options' ); 373 $checked = ( $options['animate'] ) ? ' checked="checked" ' : ''; 374 echo "<input name='tdd_pb_options[animate]' id='animate' type='checkbox' ". $checked ."> <br /> "; 375 _e( "<small>This script depends on jQuery, so it will ensure that is loaded as well</small>", 'tdd_pb' ); 376 } 377 378 //Default CSS 379 function tdd_pb_admin_form_default_css() { 380 $options = get_option( 'tdd_pb_options' ); 381 $checked = ( $options['default_css'] ) ? ' checked="checked" ' : ''; 382 echo "<input name='tdd_pb_options[default_css]' id='default_css' type='checkbox' ".$checked.">"; 383 } 384 385 386 //Percentage displays section header 387 function 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' ); 389 } 390 391 392 //Percent Display 393 function tdd_pb_admin_form_perecent_display() { 394 $options = get_option( 'tdd_pb_options' ); 395 $checked = ( $options['display_percentage'] ) ? ' checked="checked" ' : ''; 396 echo "<input name='tdd_pb_options[display_percentage]' id='display_percentage' type='checkbox' ". $checked .">"; 397 } 398 399 //percentage_color 400 function tdd_pb_admin_form_percentage_color() { 401 $options = get_option( 'tdd_pb_options' ); 402 _e( "#<input name='tdd_pb_options[percentage_color]' id='percentage_color' type='text' value='{$options['percentage_color']}' maxlength='6' size='6' />", 'tdd_pb' ); 403 } 404 405 function tdd_pb_admin_form_bar_background_color() { 406 $options = get_option( 'tdd_pb_options' ); 407 echo "#<input name='tdd_pb_options[bar_background_color]' id='bar_backround_color' type='text' value='{$options['bar_background_color']}' maxlength='6' size='6' />"; 408 } 409 410 //validate 411 function 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 418 return $input; 419 } 373 /** 374 * Class sets up and handles the global settings page for the progress bar. Settings sub-panel is attached to the custom post type menu. 375 */ 376 class TDD_PB_Admin_Settings { 377 378 function __construct(){ 379 add_action( 'admin_menu', array( $this, 'add_submenu' ) ); 380 add_action( 'admin_init', array( $this, 'register_settings' ) ); 381 } 382 383 /** 384 * Add the sub-menu to the Progress Bars custom post type. 385 */ 386 function add_submenu(){ 387 add_submenu_page( 'edit.php?post_type=tdd_pb', 'TDD Progress Bars - Settings', 'Settings', 'manage_options', 'settings', array( $this, 'render_settings_page' ) ); 388 } 389 390 /** 391 * Renders the settings page. Fired via callback in $this->add_submenu 392 */ 393 function render_settings_page(){ 394 ?> 395 <div class="wrap"> 396 <?php screen_icon( 'plugins' ); ?> 397 <h2><?php _e( 'TDD Progress Bars', 'tdd_pb' ); ?></h2> 398 399 <?php if ( isset( $_GET['settings-updated'] ) && $_GET['settings-updated'] == true ): ?> 400 <div class="updated"><p><strong><?php _e('Settings saved.'); ?></strong></p></div> 401 <?php endif; ?> 402 403 <form action="options.php" method="post"> 404 <?php settings_fields( 'tdd_pb_options' ); ?> 405 <?php do_settings_sections( __FILE__ ); ?> 406 <input name="Submit" type="submit" value="<?php _e( 'Save Changes', 'tdd_pb' ); ?>" class="button-primary" /> 407 </form> 408 </div> 409 <?php 410 } 411 412 /** 413 * Hooked in the construct() to admin_init 414 */ 415 function register_settings(){ 416 register_setting( 'tdd_pb_options', 'tdd_pb_options', array( $this, 'validate' ) ); 417 418 //register Scripts and Styles section & controls 419 add_settings_section( 'tdd_pb_sas', __( 'Scripts and Styles', 'tdd_pb' ), array( $this, 'sasheader' ), __FILE__ ); 420 add_settings_field( 'animate', __( 'Animate Bars', 'tdd_pb' ), array( $this, 'setting_animate' ), __FILE__ , 'tdd_pb_sas' ); 421 add_settings_field( 'default_css', __( 'Use Default CSS', 'tdd_pb' ), array( $this, 'setting_css' ), __FILE__, 'tdd_pb_sas' ); 422 add_settings_field( 'bar_background_color', __( 'Color of Bar Background', 'tdd_pb' ), array( $this, 'setting_bar_background_color' ), __FILE__, 'tdd_pb_sas' ); 423 add_settings_field( 'single_height', __( 'Default height for a single progress bar' ), array( $this, 'setting_default_single_height' ), __FILE__, 'tdd_pb_sas' ); 424 add_settings_field( 'race_height', __( 'Default height when multiple bars are shown together, sometimes called "racing"' ), array( $this, 'setting_default_race_height' ), __FILE__, 'tdd_pb_sas' ); 425 426 //register Percent section & controls 427 add_settings_section( 'tdd_pb_percent', __( 'Text Overlay Displays', 'tdd_pb' ), array( $this, 'percentheader' ), __FILE__ ); 428 add_settings_field( 'display_percentage', __( 'Display Text on the Bar', 'tdd_pb' ), array( $this, 'setting_perecent_display' ), __FILE__, 'tdd_pb_percent' ); 429 add_settings_field( 'percentage_color', __( 'Color of Overlay Text', 'tdd_pb' ), array( $this, 'setting_percentage_color' ), __FILE__, 'tdd_pb_percent' ); 430 431 } 432 433 function get_options( $options = '' ){ 434 if ( !$options ) 435 $options = get_option('tdd_pb_options'); 436 $mergedoptions = wp_parse_args( $options, array( 437 'animate' => true, 438 'default_css' => true, 439 'bar_background_color' => '333333', 440 'single_height' => '50', 441 'race_height' => '25', 442 'display_percentage' => true, 443 'percentage_color' => 'ececec', 444 ) ); 445 446 return $mergedoptions; 447 } 448 449 function sasheader() { 450 _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'd rather not load the required javascript)</p>", 'tdd_pb' ); 451 } 452 453 //Animate Checkbox 454 function setting_animate() { 455 $options = $this->get_options(); 456 ?> 457 <input name="tdd_pb_options[animate]" id="animate" type="checkbox" <?php checked( $options['animate'] ); ?>> <br /> 458 <?php _e( "<small>This script depends on jQuery, so it will ensure that is loaded as well</small>", 'tdd_pb' ); ?> 459 <? 460 } 461 462 //Default CSS Checkbox 463 function setting_css() { 464 $options = $this->get_options(); 465 ?> 466 <input name="tdd_pb_options[default_css]" id="default_css" type="checkbox" <?php checked( $options['default_css'] ); ?>> 467 <?php 468 } 469 470 function setting_bar_background_color() { 471 //TODO: For all these color options, implement a color picker. 472 $options = $this->get_options(); 473 ?> 474 <input name="tdd_pb_options[bar_background_color]" id="bar_backround_color" type="text" value="<?php echo tdd_pb_sanitize_color_hex_raw( $options['bar_background_color'] ); ?>" size="6" class="color" /> 475 <?php 476 } 477 478 function setting_default_single_height() { 479 $options = $this->get_options(); 480 ?> 481 <input name="tdd_pb_options[single_height]" id="single_height" type="text" value="<?php echo absint( $options['single_height'] ); ?>" size="3" />px 482 <?php 483 } 484 485 function setting_default_race_height() { 486 $options = $this->get_options(); 487 ?> 488 <input name="tdd_pb_options[race_height]" id="race_height" type="text" value="<?php echo absint( $options['race_height'] ); ?>" size="3" />px 489 <?php 490 } 491 492 //Percentage displays section header 493 function percentheader() { 494 _e( "<p>This is a global control to turn on and off text being displayed on the bar. Individual bars may optionally show the percentage, text (x of y), or both, however nothing will show if this box is unchecked.</p>", 'tdd_pb' ); 495 } 496 497 //Percent Display Checkbox 498 function setting_perecent_display() { 499 $options = $this->get_options(); 500 ?> 501 <input name="tdd_pb_options[display_percentage]" id="display_percentage" type="checkbox" <?php checked( $options['display_percentage'] ) ?>> 502 <?php 503 } 504 505 //percentage_color 506 function setting_percentage_color() { 507 $options = $this->get_options(); 508 ?> 509 <input name="tdd_pb_options[percentage_color]" id="percentage_color" class="color" type="text" value="<?php echo tdd_pb_sanitize_color_hex_raw( $options['percentage_color'] ); ?>" size="6" /> 510 <?php 511 } 512 513 //validate 514 function validate( $input ) { 515 //whitelist checkboxes (add them back in, even if false) 516 $output['display_percentage'] = isset( $input['display_percentage'] ) ? true : false; 517 $output['animate'] = isset( $input['animate'] ) ? true : false; 518 $output['default_css'] = isset( $input['default_css'] ) ? true : false; 519 520 //Sanitize other options 521 if ( ! empty( $input['bar_background_color'] ) ) 522 $output['bar_background_color'] = tdd_pb_sanitize_color_hex_raw( $input['bar_background_color'] ); 523 else 524 525 unset( $output['bar_background_color'] ); 526 527 if ( ! empty( $input['single_height'] ) ) 528 $output['single_height'] = absint( $input['single_height'] ); 529 else 530 unset( $output['single_height'] ); 531 532 if ( ! empty( $input['race_height'] ) ) 533 $output['race_height'] = absint( $input['race_height'] ); 534 else 535 unset( $output['race_height'] ); 536 537 if ( ! empty( $input['percentage_color'] ) ) 538 $output['percentage_color'] = tdd_pb_sanitize_color_hex_raw( $input['percentage_color'] ); 539 else 540 unset( $output['percentage_color'] ); 541 542 //We now need to set all the array indexes that are blank to their default values. 543 $mergedoutput = $this->get_options( $output ); 544 return $mergedoutput; 545 } 546 547 } 548 new TDD_PB_Admin_Settings; -
tdd-progress-bar/trunk/inc/widget.php
r499505 r549997 5 5 6 6 //Initalize/Register widget 7 add_action( 'widgets_init', 'tdd_progress_register_widget' );8 7 function tdd_progress_register_widget() { 9 8 register_widget( 'TDD_Progress_Widget' ); 10 9 } 10 11 12 13 14 15 16 17 18 19 20 21 22 11 23 12 24 class TDD_Progress_Widget extends WP_Widget { 13 14 25 function TDD_Progress_Widget() { 15 26 $widget_opts = array( … … 19 30 $this->WP_Widget( 'TDD_Progress_Widget', 'TDD Progress Bars', $widget_opts ); 20 31 } 21 32 22 33 function form($instance){ 23 34 $defaults = array( 24 35 'title' => 'Progress', 25 'ids' => '',36 'ids' => , 26 37 'desc' => '', 27 38 ); 28 39 29 40 //merge defaults with existing instance 30 41 $instance = wp_parse_args ( (array) $instance, $defaults ); … … 33 44 $desc = $instance['desc']; 34 45 ?> 35 <p>Title: <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" /></p> 46 <p> 47 <label for="<?php echo $this->get_field_id( 'title' ); ?>">Title: </label> 48 <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" /> 49 </p> 36 50 37 <p>Progress Bar IDs: <input class="widefat" id="<?php echo $this->get_field_id( 'ids' ); ?>" name="<?php echo $this->get_field_name( 'ids' ); ?>" type="text" value="<?php echo esc_attr( $ids ); ?>" /><br><small>Comma separated</small></p> 38 39 <p>Description: 40 <textarea class="widefat" id="<?php echo $this->get_field_id( 'desc '); ?>" name="<?php echo $this->get_field_name( 'desc' ); ?>"><?php echo esc_attr($desc); ?></textarea> 51 <p> 52 <label for="<?php echo $this->get_field_id( 'ids' ); ?>">Progress Bars: </label><br> 53 <select class="widefat chzn-select" style="width:220px" data-placeholder="Select progress bars to show" id="<?php echo $this->get_field_id( 'ids' ); ?>" name="<?php echo $this->get_field_name( 'ids' ); ?>[]" multiple> 54 <?php 55 $bars = new WP_Query( array( 56 'post_type' => 'tdd_pb', 57 'posts_per_page' => -1 58 )); 59 while ( $bars->have_posts() ): $bars->the_post(); 60 if ( in_array( get_the_ID(), (array) $ids ) ) 61 $selected = "selected='selected'"; 62 else 63 $selected = ''; 64 echo '<option value="' . get_the_ID() . '"' . $selected . '>'; 65 the_title(); 66 echo '</option>'; 67 endwhile; 68 wp_reset_postdata(); 69 ?> 70 </select><br> 71 <script>jQuery(".chzn-select").chosen();</script> <?php /* This entire form is ajax refreshed, putting the call here makes it stay bound on-save */ ?> 72 <small>Maximum of 20 will be shown in one block</small> 73 <!--<input class="widefat" id="<?php echo $this->get_field_id( 'ids' ); ?>" name="<?php echo $this->get_field_name( 'ids' ); ?>" type="text" value="<?php echo esc_attr( $ids ); ?>" /><br><small>Comma separated</small>--></p> 74 75 <p> 76 <label for="<?php echo $this->get_field_id( 'desc' ); ?>">Description:</label> 77 <textarea class="widefat" id="<?php echo $this->get_field_id( 'desc '); ?>" name="<?php echo $this->get_field_name( 'desc' ); ?>"><?php echo esc_attr($desc); ?></textarea> 78 </p> 41 79 42 80 <?php … … 46 84 $instance = $old_instance; 47 85 $instance['title'] = strip_tags ( $new_instance['title'] ); 48 $instance['ids'] = strip_tags($new_instance['ids'] );86 $instance['ids'] = $new_instance['ids'] ); 49 87 $instance['desc'] = strip_tags( $new_instance['desc'] ); 50 88 return $instance; 51 89 } 52 90 53 91 function widget( $args, $instance ){ 54 92 extract($args); … … 57 95 58 96 $title = apply_filters( 'widget_title', $instance['title'] ); 59 if ( !empty($title) ){ echo $before_title . $title . $after_title; } 60 61 $ids = explode ( ',', $instance['ids'] ); 62 97 if ( !empty($title) ){ echo $before_title . sanitize_text_field( $title ) . $after_title; } 98 63 99 $args = array( 64 'ids' => $ids,100 'ids' => , 65 101 ); 66 102 67 103 echo tdd_pb_get_bars( $args ); 68 69 echo ( $instance['desc'] ) ? wpautop( $instance['desc']) : '' ;70 104 105 echo ( $instance['desc'] ) ? wpautop() : '' ; 106 71 107 echo $after_widget; 72 108 } -
tdd-progress-bar/trunk/readme.txt
r523224 r549997 5 5 Requires at least: 3.3 6 6 Tested up to: 3.3.1 7 Stable tag: 0. 47 Stable tag: 0. 8 8 9 Configure and display any number of percent-complete progress bars. 89 Configure and display any number of percent-complete progress bars. 10 10 11 11 == Description == … … 24 24 25 25 = It doesn't look right.. = 26 This 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). 26 This 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 27 28 28 = How do I use the filter hook to modify a percentage? = … … 54 54 * Race multiple bars: `[progress id=32,35,54]` 55 55 * Set the bar's width: `[progress ids=12,33 width="25%"]` 56 56 57 * Align Center: `[progress ids=4 width="50%" class="aligncenter"]` 57 58 58 59 Note that "id" and "ids" are interchangeable 59 60 60 Or use the widget which a ccepts a comma separated list of Ids to display.61 Or use the widget which a 61 62 62 63 == Changelog == 64 65 66 67 68 69 70 63 71 64 72 = 0.4 = -
tdd-progress-bar/trunk/tdd-progress-bar.php
r523224 r549997 4 4 Plugin URI: http://github.com/tddewey/tdd-progress 5 5 Description: Manage and display progress bars 6 Version: 0. 46 Version: 0. 7 7 Author: Taylor D. Dewey 8 8 Author URI: http://websitesthatdontsuck.com … … 140 140 add_action( 'init', 'tdd_pb_register_post_type' ); 141 141 142 /*143 * Set up admin menus144 */145 function tdd_pb_admin_menu(){146 add_submenu_page( 'edit.php?post_type=tdd_pb', 'TDD Progress Bars - Settings', 'Settings', 'manage_options', __FILE__, 'tdd_pb_view_settings' );147 }148 add_action( 'admin_menu', 'tdd_pb_admin_menu' );149 142 150 143 /* … … 177 170 'width' => 'auto', 178 171 'class' => '', 172 179 173 ), $args ); 180 174 … … 190 184 'width' => $args['width'], 191 185 'class' => $args['class'], 186 192 187 )); 193 188 … … 199 194 add_shortcode('tdd_pb', 'tdd_pb_shortcode' ); 200 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 201 257 202 258 /* 203 259 * Returns a progress bar container with 1 or more progress bars 260 261 204 262 * 205 263 * @param array $ids An array of the ids of progress bars to fetch. … … 209 267 */ 210 268 function tdd_pb_get_bars( $args ){ 211 $ defaults = array(269 $defaults = array( 212 270 'ids' => array(), 213 271 'width' => 'auto', 272 214 273 'class' => '', 215 274 'default_color' => 'tdd_pb_red', 216 ) ;275 ); 217 276 218 277 $tdd_pb_options = get_option( 'tdd_pb_options'); 219 278 220 //parse incoming arguments against default. 221 $args = wp_parse_args( $args, $defaults ); 222 223 //Filter the array to ensure we're getting things that look like integers. Will also filter out blank array items (i.e. '' ) 279 //Filter the array to ensure we're getting things that look like integers. Will also filter out blank array items 224 280 $idsarr = array_filter( $args['ids'], 'is_numeric' ); 225 281 226 //count if this is a race (more than one progress bar being displayed. The race format can also be forced by passing "race" in the $class argument) 282 //count if this is a race (more than one progress bar being displayed. The race format can also be forced by passing "tdd_pb_race" in the $class argument) 283 if ( count ( $idsarr ) > 1 ){ 284 $race = 'tdd_pb_race'; 285 if ( ! $args['height'] ){ 286 $args['height'] = $tdd_pb_options['race_height'] . 'px'; 287 } 288 } else { 289 $race = ''; 290 if ( ! $args['height'] ){ 291 $args['height'] = $tdd_pb_options['single_height'] . 'px'; 292 } 293 } 294 295 227 296 $race = ( count( $idsarr ) > 1 ) ? 'tdd_pb_race' : ''; 228 297 229 298 //Set up our global container 230 $return = '<div class="tdd_pb_global_container '.$race.' '.$args['class'].'" style="width:'.strip_tags( $args['width'] ).'">'; 299 $return = '<div class="tdd_pb_global_container ' . $race . ' '. sanitize_html_class( $args['class'] ); 300 $return .= '" style="width:' . esc_attr(strip_tags( $args['width'] ) ) . '">'; 231 301 232 302 //If there are no ids to display, this is kind of a moot proccess - so let's say so: 233 303 if ( count( $idsarr ) <= 0 ){ 234 $return .= '<p>' . __( 'No progress bars were set, so there is nothing to display', 'tdd_pb' ) . '</p></div>';304 $return .= '<p>' . __( 'No progress bars were set, so there is nothing to display', 'tdd_pb' ). '</p></div>'; 235 305 return $return; 236 306 } … … 240 310 $tdd_pb_query->query(array( 241 311 'post_type' => 'tdd_pb', 242 'posts_per_page' => -1,312 'posts_per_page' => , 243 313 'post__in' => $idsarr, 244 314 '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...246 315 )); 247 316 … … 250 319 $return .= '<p>'. __( 'No progress bars found', 'tdd_pb' ) . '</p></div>'; 251 320 return $return; 252 321 } 253 322 254 323 while ( $tdd_pb_query->have_posts() ): $tdd_pb_query->the_post(); 255 $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 ); 324 $color = get_post_meta( get_the_ID(), '_tdd_pb_color', true ); 325 $custom_color = get_post_meta( get_the_ID(), '_tdd_pb_custom_color', true ); 326 $percentage = get_post_meta( get_the_ID(), '_tdd_pb_percentage', true ); 327 $start = get_post_meta( get_the_ID(), '_tdd_pb_start', true ); 328 $end = get_post_meta( get_the_ID(), '_tdd_pb_end', true ); 329 $input_method = get_post_meta( get_the_ID(), '_tdd_pb_input_method', true ); 330 $percentage_display = get_post_meta( get_the_ID(), '_tdd_pb_percentage_display', true ); 331 $xofy_display = get_post_meta( get_the_ID(), '_tdd_pb_xofy_display', true ); 332 333 //Get the calculated percentage 334 if ( $input_method == 'xofy' && $end > 0 ){ 335 $start = intval( $start ); 336 $end = intval( $end ); 337 $calcpercentage = round( $start/$end*100, 2 ); 264 338 } else { 265 339 $calcpercentage = $percentage; … … 269 343 $calcpercentage = apply_filters( 'tdd_pb_calculated_percentage', $calcpercentage, get_the_ID() ); 270 344 271 $color = strip_tags( get_post_meta( get_the_ID(), '_tdd_pb_color', true ) ); 272 //if no color, define a default 273 $color = (!$color) ? $args['default_color'] : 'tdd_pb_'.$color; 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 .=' ' . $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>'; 345 //Fallback to default bar color 346 $color_class = ( $color ) ? sanitize_html_class( 'tdd_pb_' . $color ) : $args['default_color']; 347 348 //Are we displaying text on the bar? Potentially... (there's a global setting that can override this) 349 $text_on_bar = ''; 350 if ( $percentage_display == 'on' || $percentage_display === '' ) 351 $text_on_bar .= absint( $calcpercentage ) .'%'; 352 353 if ( $xofy_display == 'on' ) 354 $text_on_bar .=' ' .intval( $start ) . ' ' . __( 'of', 'tdd_pb' ) . ' ' . intval( $end ); 355 356 $barargs = array( 357 'percentage' => $calcpercentage, 358 'text_on_bar' => $text_on_bar, 359 'title' => get_the_title(), 360 'classes' => array(), 361 'width' => esc_attr( $args['width'] ), 362 'height' => esc_attr( $args['height'] ), 363 'color_class' => $color_class, 364 'custom_color' => tdd_pb_sanitize_color_hex_raw( $custom_color ) 365 ); 366 367 $return .= tdd_pb_render_bar( $barargs ); 289 368 290 369 endwhile; 370 291 371 292 372 //Close the progress bar container, and return everything to screen. … … 294 374 return $return; 295 375 } 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394
Note: See TracChangeset
for help on using the changeset viewer.