default_device_bg = shiword_get_default_colors('out'); $this->default_device_colors = shiword_get_default_colors('in'); $this->page = $page = add_theme_page(__( 'Custom Colors', 'shiword' ), __( 'Custom Colors', 'shiword' ), 'edit_theme_options' , 'device-color' , array( &$this , 'admin_page' )); add_action( "admin_print_scripts-$page" , array(&$this, 'js_includes' ) ); add_action( "admin_print_styles-$page" , array(&$this, 'css_includes' ) ); add_action( "admin_head-$page" , array(&$this, 'take_action' ), 50 ); } /* Get the current step. */ function step() { if ( ! isset( $_GET['step'] ) ) return 1; $step = (int) $_GET['step']; if ( $step < 1 || 3 < $step ) $step = 1; return $step; } /* Set up the enqueue for the JavaScript files. */ function js_includes() { global $shiword_version; wp_enqueue_script( 'sw-custom-colors-script', get_template_directory_uri() . '/js/admin-custom_colors.dev.js', array('farbtastic','jquery','jquery-ui-slider','jquery-ui-draggable'), $shiword_version, true ); //shiword js } /* Set up the enqueue for the CSS files */ function css_includes() { wp_enqueue_style( 'sw-custom-colors-style', get_template_directory_uri() . '/css/admin-custom_colors.css', array( 'farbtastic' ), false, 'screen' ); $color = get_background_color(); if ( ! $color ) $color = 'b6b6b6'; echo ''; } /* Options check. */ function take_action() { if ( ! current_user_can( 'edit_theme_options' ) ) return; $colors = get_option( 'shiword_colors' ); //if options are empty, sets the default values if ( empty( $colors ) ) { $colors = array_merge( $this->default_device_colors , $this->default_device_bg ); update_option( 'shiword_colors' , $colors ); } } /* Process the default headers */ function process_default_device_images() { global $shiword_default_device_images; if ( !empty($this->headers) ) return; if ( !isset($shiword_default_device_images) ) return; $this->default_device_images = $shiword_default_device_images; foreach ( array_keys($this->default_device_images) as $header ) { $this->default_device_images[$header]['url'] = sprintf( $this->default_device_images[$header]['url'], get_template_directory_uri(), get_stylesheet_directory_uri() ); } } /* Display UI for selecting one of several default headers. */ function show_default_header_selector() { global $shiword_colors; echo '
'; foreach ( $this->default_device_images as $header_key => $header ) { $header_url = $header['url']; $header_desc = $header['description']; echo ''; } echo '
'; } function build_style() { global $shiword_colors; $device_rgba = shiword_hex2rgba( $shiword_colors['device_color'], $shiword_colors['device_opacity']); ?> build_style(); ?>

__('Background', 'shiword' ), 'menu2' => __('Borders', 'shiword' ), 'menu3' => __('Text', 'shiword' ), 'menu4' => __('Links', 'shiword' ), 'menu5' => __('Highlighted Links', 'shiword' ), 'menu6' => __('Inner borders', 'shiword' ), 'main3' => __('Links', 'shiword' ), 'main4' => __('Highlighted Links', 'shiword' ), ); $this->process_default_device_images(); ?>

updated ) ) { ?>

Visit your site to see how it looks.' , 'shiword' ) , home_url( '/' ) ); ?>

show_preview(); ?>

»



default_device_images ) ) { ?>
show_default_header_selector(); ?>
 -   - 
[0-100] %
 - 
 - 

»

default_device_colors as $key => $val ) { ?> '; elseif ( $key == 'menu1' ) echo ''; ?>
' . __( 'Main Content', 'shiword' ) . '
' . __( 'Pages Menu and Floating Menu', 'shiword' ) . '
 - 

step_1(); check_admin_referer( 'load-custom-image' , 'nonce-load-custom-image' ); $overrides = array( 'test_form' => false ); $file = wp_handle_upload( $_FILES['import'] , $overrides ); if ( isset($file['error']) ) wp_die( $file['error'], __( 'Image Upload Error', 'shiword' ) ); $url = $file['url']; $type = $file['type']; $file = $file['file']; $filename = basename($file); // Construct the object array $object = array( 'post_title' => $filename, 'post_content' => $url, 'post_mime_type' => $type, 'guid' => $url); // Save the data $id = wp_insert_attachment( $object , $file ); // Add the meta-data wp_update_attachment_metadata( $id , wp_generate_attachment_metadata( $id , $file ) ); $shiword_colors['device_image'] = esc_url($url); update_option( 'shiword_colors' , $shiword_colors ); do_action( 'wp_create_file_in_uploads' , $file , $id ); // For replication return $this->finished(); } /* Run third step of custom colors page - updates color options. */ function step_3() { check_admin_referer( 'set-custom-colors' , 'nonce-set-custom-colors' ); if ( ! current_user_can( 'edit_theme_options' ) ) return $this->step_1(); $shiword_colors = get_option( 'shiword_colors' ); //if options are empty, sets the default values if ( empty( $shiword_colors ) ) { $shiword_colors = array_merge( $this->default_device_colors , $this->default_device_bg ); update_option( 'shiword_colors' , $shiword_colors ); } if ( empty( $_POST ) ) return $this->step_1(); if ( isset( $_POST['removedeviceimage'] ) ) { $shiword_colors['device_image'] = '' ; update_option( 'shiword_colors' , $shiword_colors ); return $this->finished(); } $shiword_colors['device_textcolor'] = $this->default_device_bg['device_textcolor']; if ( isset( $_POST['devicetextcolor'] ) ) { $_POST['devicetextcolor'] = str_replace( '#' , '' , $_POST['devicetextcolor'] ); if ( 'transparent' == $_POST['devicetextcolor'] ) { $shiword_colors['device_textcolor'] = 'transparent'; } else { $color = preg_replace( '/[^0-9a-fA-F]/' , '' , $_POST['devicetextcolor'] ); if ( strlen($color) == 6 || strlen($color) == 3 ) $shiword_colors['device_textcolor'] = '#' . $color; } } $shiword_colors['device_color'] = $this->default_device_bg['device_color']; if ( isset( $_POST['devicecolor'] ) ) { $_POST['devicecolor'] = str_replace( '#' , '' , $_POST['devicecolor'] ); if ( 'transparent' == $_POST['devicecolor'] ) { $shiword_colors['device_color'] = 'transparent'; } else { $color = preg_replace( '/[^0-9a-fA-F]/' , '' , $_POST['devicecolor'] ); if ( strlen($color) == 6 || strlen($color) == 3 ) $shiword_colors['device_color'] = '#' . $color; } } $shiword_colors['device_opacity'] = $this->default_device_bg['device_opacity']; if ( isset( $_POST['deviceopacity'] ) ) { $alpha = intval( $_POST['deviceopacity'] ); if ( ( $alpha < 0 ) || ( $alpha > 100 )) $alpha = 100; $shiword_colors['device_opacity'] = strval( $alpha ); } $shiword_colors['device_button'] = $this->default_device_bg['device_button']; if ( isset( $_POST['devicebuttonborder'] ) ) { $_POST['devicebuttonborder'] = str_replace( '#' , '' , $_POST['devicebuttonborder'] ); if ( 'transparent' == $_POST['devicebuttonborder'] ) { $shiword_colors['device_button'] = 'transparent'; } else { $color = preg_replace( '/[^0-9a-fA-F]/' , '' , $_POST['devicebuttonborder'] ); if ( strlen($color) == 6 || strlen($color) == 3 ) $shiword_colors['device_button'] = '#' . $color; } } $shiword_colors['device_button_style'] = $this->default_device_bg['device_button_style']; if ( isset( $_POST['devicebuttonstyle'] ) ) { $shiword_colors['device_button_style'] = ( in_array( $_POST['devicebuttonstyle'], array( 'light', 'dark' ) ) ) ? $_POST['devicebuttonstyle'] : 'light'; } if ( isset($_POST['default-device-image']) ) { $this->process_default_device_images(); if ( isset($this->default_device_images[$_POST['default-device-image']]) ) $shiword_colors['device_image'] = esc_url( $this->default_device_images[$_POST['default-device-image']]['url'] ); } foreach ( $this->default_device_colors as $key => $val ) { if ( isset( $_POST[$key] ) ) { $_POST[$key] = str_replace( '#' , '' , $_POST[$key] ); if ( 'transparent' == $_POST[$key] ) { $shiword_colors[$key] = 'transparent'; } else { $color = preg_replace( '/[^0-9a-fA-F]/' , '' , $_POST[$key] ); if ( strlen($color) == 6 || strlen($color) == 3 ) { $shiword_colors[$key] = '#' . $color ; } else { $shiword_colors[$key] = $val ; } } } else { $shiword_colors[$key] = $val ; } } update_option( 'shiword_colors' , $shiword_colors ); return $this->finished(); } /* Display last step of custom header image page. */ function finished() { global $shiword_colors; $shiword_colors = shiword_get_colors(); $this->updated = true; $this->init(); $this->step_1(); } /* Display the page based on the current step. */ function admin_page() { if ( ! current_user_can( 'edit_theme_options' ) ) wp_die( __( 'You do not have permission to customize headers.', 'shiword' ) ); $step = $this->step(); if ( 1 == $step ) $this->step_1(); elseif ( 2 == $step ) $this->step_2(); elseif ( 3 == $step ) $this->step_3(); } } ?>