Changeset 13788
- Timestamp:
- 03/21/2010 06:06:18 AM (15 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/custom-background.php
r13765 r13788 1 1 <?php 2 2 /** 3 * The custom background imagescript.3 * The custom background script. 4 4 * 5 5 * @package WordPress … … 8 8 9 9 /** 10 * The custom background imageclass.10 * The custom background class. 11 11 * 12 * @since unknown12 * @since 3.0 13 13 * @package WordPress 14 14 * @subpackage Administration … … 29 29 * 30 30 * @var callback 31 * @since unknown31 * @since 3.0 32 32 * @access private 33 33 */ … … 37 37 * PHP4 Constructor - Register administration header callback. 38 38 * 39 * @since unknown39 * @since 3.0 40 40 * @param callback $admin_header_callback 41 41 * @param callback $admin_image_div_callback Optional custom image div output callback. … … 50 50 * Set up the hooks for the Custom Background admin page. 51 51 * 52 * @since unknown52 * @since 3.0 53 53 */ 54 54 function init() { … … 58 58 $page = add_theme_page(__('Background'), __('Background'), 'switch_themes', 'custom-background', array(&$this, 'admin_page')); 59 59 60 add_action(" admin_print_scripts-$page", array(&$this, 'js_includes'));61 add_action(" admin_print_styles-$page", array(&$this, 'css_includes'));62 add_action(" admin_head-$page", array(&$this, 'js'), 50);63 add_action("admin_head-$page", array(&$this, 'take_action'), 49); 60 add_action("load-$page", array(&$this, 'admin_load')); 61 add_action("load-$page", array(&$this, 'take_action'), 49); 62 add_action("load-$page", array(&$this, 'handle_upload'), 49); 63 64 64 if ( $this->admin_header_callback ) 65 65 add_action("admin_head-$page", $this->admin_header_callback, 51); … … 67 67 68 68 /** 69 * Get the current step. 70 * 71 * @since unknown 72 * 73 * @return int Current step 74 */ 75 function step() { 76 if ( ! isset( $_GET['step'] ) ) 77 return 1; 78 79 $step = (int) $_GET['step']; 80 if ( $step < 1 || 3 < $step ) 81 $step = 1; 82 83 return $step; 84 } 85 86 /** 87 * Set up the enqueue for the JavaScript files. 88 * 89 * @since unknown 90 */ 91 function js_includes() { 92 wp_enqueue_script('farbtastic'); 93 } 94 95 /** 96 * Set up the enqueue for the CSS files 97 * 98 * @since unknown 99 */ 100 function css_includes() { 69 * Set up the enqueue for the CSS & JavaScript files. 70 * 71 * @since 3.0 72 */ 73 function admin_load() { 74 wp_enqueue_script('custom-background'); 101 75 wp_enqueue_style('farbtastic'); 102 76 } … … 105 79 * Execute custom background modification. 106 80 * 107 * @since unknown81 * @since 3.0 108 82 */ 109 83 function take_action() { 110 if ( ! current_user_can('switch_themes') )111 return;112 84 113 85 if ( empty($_POST) ) … … 116 88 check_admin_referer('custom-background'); 117 89 118 if ( isset($_POST['reset-background']) ) 90 // @TODO: No UI entry point for this: 91 if ( isset($_POST['reset-background']) ) { 119 92 remove_theme_mods(); 93 return; 94 } 95 if ( isset($_POST['remove-background']) ) { 96 // @TODO: Uploaded files are not removed here. 97 set_theme_mod('background_image', ''); 98 } 99 120 100 if ( isset($_POST['background-repeat']) ) { 121 101 if ( in_array($_POST['background-repeat'], array('repeat', 'no-repeat')) ) … … 139 119 set_theme_mod('background_attachment', $attachment); 140 120 } 141 if ( isset($_POST['remove-background']) ) 142 set_theme_mod('background_image', ''); 143 if ( isset( $_POST['background-color'] ) ) { 121 if ( isset($_POST['background-color']) ) { 144 122 $color = preg_replace('/[^0-9a-fA-F]/', '', $_POST['background-color']); 145 123 if ( strlen($color) == 6 || strlen($color) == 3 ) … … 153 131 154 132 /** 155 * Execute Javascript depending on step. 156 * 157 * @since unknown 158 */ 159 function js() { 160 $this->js_1(); 161 } 162 163 /** 164 * Display Javascript based on Step 1. 165 * 166 * @since unknown 167 */ 168 function js_1() { ?> 169 <script type="text/javascript"> 170 var buttons = ['#pickcolor'], 171 farbtastic; 172 173 function pickColor(color) { 174 jQuery('#background-color').val(color); 175 farbtastic.setColor(color); 176 jQuery('#custom-background-image').css('background-color', color); 177 } 178 179 jQuery(document).ready(function() { 180 jQuery('#pickcolor').click(function() { 181 jQuery('#colorPickerDiv').show(); 182 }); 183 jQuery('#background-color').keyup(function() { 184 var _hex = jQuery('#background-color').val(); 185 var hex = _hex; 186 if ( hex[0] != '#' ) 187 hex = '#' + hex; 188 hex = hex.replace(/[^#a-fA-F0-9]+/, ''); 189 if ( hex != _hex ) 190 jQuery('#background-color').val(hex); 191 if ( hex.length == 4 || hex.length == 7 ) 192 pickColor( hex ); 193 }); 194 195 farbtastic = jQuery.farbtastic('#colorPickerDiv', function(color) { pickColor(color); }); 196 pickColor('#<?php background_color(); ?>'); 197 }); 198 199 jQuery(document).mousedown(function(){ 200 hide_picker(); // Make the picker disappear if you click outside its div element 201 }); 202 203 function hide_picker(what) { 204 var update = false; 205 jQuery('#colorPickerDiv').each(function(){ 206 var id = jQuery(this).attr('id'); 207 if (id == what) { 208 return; 209 } 210 var display = jQuery(this).css('display'); 211 if (display == 'block') { 212 jQuery(this).fadeOut(2); 213 } 214 }); 215 } 216 217 </script> 218 <?php 219 } 220 221 /** 222 * Display first step of custom background image page. 223 * 224 * @since unknown 225 */ 226 function step_1() { 133 * Display the custom background page. 134 * 135 * @since 3.0 136 */ 137 function admin_page() { 227 138 ?> 228 139 <div class="wrap" id="custom-background"> … … 240 151 } else { 241 152 if ( $bgcolor = get_background_color() ) 242 $bgcolor = ' style="background-color: #' . $bgcolor . ';"'; 243 else 244 $bgcolor = ''; 153 $bgcolor = 'background-color: #' . $bgcolor . ';'; 154 155 if ( $align = get_theme_mod('background_position', 'left') ) 156 $align = "text-align: $align;"; 245 157 ?> 246 <div id="custom-background-image" <?php echo $bgcolor; ?>>158 <div id="custom-background-image" style="<?php echo $bgcolor, $align ?>"> 247 159 <?php if ( get_background_image() ) { ?> 248 160 <img class="custom-background-image" src="<?php background_image(); ?>" /> 249 161 <?php } ?> 162 <br class="clear" /> 250 163 </div> 251 164 <?php } ?> 252 165 <h3><?php _e('Change Display Options') ?></h3> 253 <form method="post" action=" <?php echo esc_attr(add_query_arg('step', 1)) ?>">166 <form method="post" action=""> 254 167 <table> 255 168 <thead> … … 315 228 316 229 <h3><?php _e('Upload New Background Image'); ?></h3> 317 <form enctype="multipart/form-data" id="uploadForm" method="POST" action=" <?php echo esc_attr(add_query_arg('step', 2)) ?>">230 <form enctype="multipart/form-data" id="uploadForm" method="POST" action=""> 318 231 <label for="upload"><?php _e('Choose an image from your computer:'); ?></label><br /><input type="file" id="upload" name="import" /> 319 232 <input type="hidden" name="action" value="save" /> … … 327 240 <h3><?php _e('Remove Background Image'); ?></h3> 328 241 <p><?php _e('This will remove the background image. You will not be able to retrieve any customizations.') ?></p> 329 <form method="post" action=" <?php echo esc_attr(add_query_arg('step', 1)) ?>">242 <form method="post" action=""> 330 243 <?php wp_nonce_field('custom-background'); ?> 331 244 <input type="submit" class="button" name="remove-background" value="<?php esc_attr_e('Remove Background'); ?>" /> 332 245 </form> 333 334 246 <?php endif; ?> 247 335 248 </div> 336 249 <?php … … 338 251 339 252 /** 340 * Display second step of custom background image page. 341 * 342 * @since unknown 343 */ 344 function step_2() { 253 * Handle a Image upload for the background image. 254 * 255 * @since 3.0 256 */ 257 function handle_upload() { 258 259 if ( empty($_FILES) ) 260 return; 261 345 262 check_admin_referer('custom-background'); 346 263 $overrides = array('test_form' => false); … … 372 289 do_action('wp_create_file_in_uploads', $file, $id); // For replication 373 290 $this->updated = true; 374 return $this->finished();375 }376 377 /**378 * Display last step of custom header image page.379 *380 * @since unknown381 */382 function finished() {383 $this->step_1();384 }385 386 /**387 * Display the page based on the current step.388 *389 * @since unknown390 */391 function admin_page() {392 if ( ! current_user_can('switch_themes') )393 wp_die(__('You do not have permission to customize the background.'));394 $step = $this->step();395 if ( 1 == $step )396 $this->step_1();397 elseif ( 2 == $step )398 $this->step_2();399 291 } 400 292 -
trunk/wp-includes/script-loader.php
r13766 r13788 407 407 'warnDelete' => __( "You are about to permanently delete this menu. \n 'Cancel' to stop, 'OK' to delete." ), 408 408 ) ); 409 410 $scripts->add( 'custom-background', "/wp-admin/js/custom-background$suffix.js", array('farbtastic'), '20100321' ); 411 $scripts->add_data( 'custom-background', 'group', 1 ); 412 // See wp_just_in_time_script_localization() for translation data for this object 413 409 414 } 410 415 } … … 510 515 511 516 /** 512 * Load localized script just in time for MCE.517 * Load localized data on print rather than initialization. 513 518 * 514 519 * These localizations require information that may not be loaded even by init. … … 527 532 'l10n_print_after' => 'try{convertEntities(autosaveL10n);}catch(e){};' 528 533 ) ); 534 535 wp_localize_script( 'custom-background', 'customBackgroundL10n', array( 536 'backgroundcolor' => '#' . get_background_color(), 537 ) ); 529 538 } 530 539
Note: See TracChangeset
for help on using the changeset viewer.