Wordpress 2.0.11
[autoinstalls/wordpress.git] / wp-content / themes / default / functions.php
index b2c78f656d67dd2521283f4ecd4b66945bfe4ff0..5f10d7f9135484a540c110ed7a33f6b7a9767bf9 100644 (file)
-<?php\r
-\r
-function kubrick_head() {\r
-       $head = "<style type='text/css'>\n<!--";\r
-       $output = '';\r
-       if ( kubrick_header_image() ) {\r
-               $url =  kubrick_header_image_url() ;\r
-               $output .= "#header { background: url('$url') no-repeat bottom center; }\n";\r
-       }\r
-       if ( false !== ( $color = kubrick_header_color() ) ) {\r
-               $output .= "#headerimg h1 a, #headerimg h1 a:visited, #headerimg .description { color: $color; }\n";\r
-       }\r
-       if ( false !== ( $display = kubrick_header_display() ) ) {\r
-               $output .= "#headerimg { display: $display }\n";\r
-       }\r
-       $foot = "--></style>\n";\r
-       if ( '' != $output )\r
-               echo $head . $output . $foot;\r
-}\r
-\r
-add_action('wp_head', 'kubrick_head');\r
-\r
-function kubrick_header_image() {\r
-       return apply_filters('kubrick_header_image', get_settings('kubrick_header_image'));\r
-}\r
-\r
-function kubrick_upper_color() {\r
-       if ( strstr( $url = kubrick_header_image_url(), 'header-img.php?' ) ) {\r
-               parse_str(substr($url, strpos($url, '?') + 1), $q);\r
-               return $q['upper'];\r
-       } else\r
-               return '69aee7';\r
-}\r
-\r
-function kubrick_lower_color() {\r
-       if ( strstr( $url = kubrick_header_image_url(), 'header-img.php?' ) ) {\r
-               parse_str(substr($url, strpos($url, '?') + 1), $q);\r
-               return $q['lower'];\r
-       } else\r
-               return '4180b6';\r
-}\r
-\r
-function kubrick_header_image_url() {\r
-       if ( $image = kubrick_header_image() )\r
-               $url = get_template_directory_uri() . '/images/' . $image;\r
-       else\r
-               $url = get_template_directory_uri() . '/images/kubrickheader.jpg';\r
-\r
-       return $url;\r
-}\r
-\r
-function kubrick_header_color() {\r
-       return apply_filters('kubrick_header_color', get_settings('kubrick_header_color'));\r
-}\r
-\r
-function kubrick_header_color_string() {\r
-       $color = kubrick_header_color();\r
-       if ( false === $color )\r
-               return 'white';\r
-\r
-       return $color;\r
-}\r
-\r
-function kubrick_header_display() {\r
-       return apply_filters('kubrick_header_display', get_settings('kubrick_header_display'));\r
-}\r
-\r
-function kubrick_header_display_string() {\r
-       $display = kubrick_header_display();\r
-       return $display ? $display : 'inline';\r
-}\r
-\r
-add_action('admin_menu', 'kubrick_add_theme_page');\r
-\r
-function kubrick_add_theme_page() {\r
-       if ( $_GET['page'] == basename(__FILE__) ) {\r
-               if ( 'save' == $_REQUEST['action'] ) {\r
-                       if ( isset($_REQUEST['njform']) ) {\r
-                               if ( isset($_REQUEST['defaults']) ) {\r
-                                       delete_option('kubrick_header_image');\r
-                                       delete_option('kubrick_header_color');\r
-                                       delete_option('kubrick_header_display');\r
-                               } else {\r
-                                       if ( '' == $_REQUEST['njfontcolor'] )\r
-                                               delete_option('kubrick_header_color');\r
-                                       else\r
-                                               update_option('kubrick_header_color', $_REQUEST['njfontcolor']);\r
-\r
-                                       if ( preg_match('/[0-9A-F]{6}|[0-9A-F]{3}/i', $_REQUEST['njuppercolor'], $uc) && preg_match('/[0-9A-F]{6}|[0-9A-F]{3}/i', $_REQUEST['njlowercolor'], $lc) ) {\r
-                                               $uc = ( strlen($uc[0]) == 3 ) ? $uc[0]{0}.$uc[0]{0}.$uc[0]{1}.$uc[0]{1}.$uc[0]{2}.$uc[0]{2} : $uc[0];\r
-                                               $lc = ( strlen($lc[0]) == 3 ) ? $lc[0]{0}.$lc[0]{0}.$lc[0]{1}.$lc[0]{1}.$lc[0]{2}.$lc[0]{2} : $lc[0];\r
-                                               update_option('kubrick_header_image', "header-img.php?upper=$uc&amp;lower=$lc");\r
-                                       }\r
-\r
-                                       if ( isset($_REQUEST['toggledisplay']) ) {\r
-                                               if ( false === get_settings('kubrick_header_display') )\r
-                                                       update_option('kubrick_header_display', 'none');\r
-                                               else\r
-                                                       delete_option('kubrick_header_display');\r
-                                       }\r
-                               }\r
-                       } else {\r
-\r
-                               if ( isset($_REQUEST['headerimage']) ) {\r
-                                       if ( '' == $_REQUEST['headerimage'] )\r
-                                               delete_option('kubrick_header_image');\r
-                                       else\r
-                                               update_option('kubrick_header_image', $_REQUEST['headerimage']);\r
-                               }\r
-\r
-                               if ( isset($_REQUEST['fontcolor']) ) {\r
-                                       if ( '' == $_REQUEST['fontcolor'] )\r
-                                               delete_option('kubrick_header_color');\r
-                                       else\r
-                                               update_option('kubrick_header_color', $_REQUEST['fontcolor']);\r
-                               }\r
-\r
-                               if ( isset($_REQUEST['fontdisplay']) ) {\r
-                                       if ( '' == $_REQUEST['fontdisplay'] || 'inline' == $_REQUEST['fontdisplay'] )\r
-                                               delete_option('kubrick_header_display');\r
-                                       else\r
-                                               update_option('kubrick_header_display', 'none');\r
-                               }\r
-                       }\r
-                       //print_r($_REQUEST);\r
-                       wp_redirect("themes.php?page=functions.php&saved=true");\r
-                       die;\r
-               }\r
-               add_action('admin_head', 'kubrick_theme_page_head');\r
-       }\r
-       add_theme_page('Customize Header', 'Header Image and Color', 'edit_themes', basename(__FILE__), 'kubrick_theme_page');\r
-}\r
-\r
-function kubrick_theme_page_head() {\r
-?>\r
-<script type="text/javascript" src="../wp-includes/js/colorpicker.js"></script>\r
-<script type='text/javascript'>\r
-// <![CDATA[\r
-       function pickColor(color) {\r
-               ColorPicker_targetInput.value = color;\r
-               kUpdate(ColorPicker_targetInput.id);\r
-       }\r
-       function PopupWindow_populate(contents) {\r
-               contents += '<br /><p style="text-align:center;margin-top:0px;"><input type="button" value="Close Color Picker" onclick="cp.hidePopup(\'prettyplease\')"></input></p>';\r
-               this.contents = contents;\r
-               this.populated = false;\r
-       }\r
-       function PopupWindow_hidePopup(magicword) {\r
-               if ( magicword != 'prettyplease' )\r
-                       return false;\r
-               if (this.divName != null) {\r
-                       if (this.use_gebi) {\r
-                               document.getElementById(this.divName).style.visibility = "hidden";\r
-                       }\r
-                       else if (this.use_css) {\r
-                               document.all[this.divName].style.visibility = "hidden";\r
-                       }\r
-                       else if (this.use_layers) {\r
-                               document.layers[this.divName].visibility = "hidden";\r
-                       }\r
-               }\r
-               else {\r
-                       if (this.popupWindow && !this.popupWindow.closed) {\r
-                               this.popupWindow.close();\r
-                               this.popupWindow = null;\r
-                       }\r
-               }\r
-               return false;\r
-       }\r
-       function colorSelect(t,p) {\r
-               if ( cp.p == p && document.getElementById(cp.divName).style.visibility != "hidden" )\r
-                       cp.hidePopup('prettyplease');\r
-               else {\r
-                       cp.p = p;\r
-                       cp.select(t,p);\r
-               }\r
-       }\r
-       function PopupWindow_setSize(width,height) {\r
-               this.width = 162;\r
-               this.height = 210;\r
-       }\r
-\r
-       var cp = new ColorPicker();\r
-       function advUpdate(val, obj) {\r
-               document.getElementById(obj).value = val;\r
-               kUpdate(obj);\r
-       }\r
-       function kUpdate(oid) {\r
-               if ( 'uppercolor' == oid || 'lowercolor' == oid ) {\r
-                       uc = document.getElementById('uppercolor').value.replace('#', '');\r
-                       lc = document.getElementById('lowercolor').value.replace('#', '');\r
-                       hi = document.getElementById('headerimage');\r
-                       hi.value = 'header-img.php?upper='+uc+'&lower='+lc;\r
-                       document.getElementById('header').style.background = 'url("<?php echo get_template_directory_uri(); ?>/images/'+hi.value+'") center no-repeat';\r
-                       document.getElementById('advuppercolor').value = '#'+uc;\r
-                       document.getElementById('advlowercolor').value = '#'+lc;\r
-               }\r
-               if ( 'fontcolor' == oid ) {\r
-                       document.getElementById('header').style.color = document.getElementById('fontcolor').value;\r
-                       document.getElementById('advfontcolor').value = document.getElementById('fontcolor').value;\r
-               }\r
-               if ( 'fontdisplay' == oid ) {\r
-                       document.getElementById('headerimg').style.display = document.getElementById('fontdisplay').value;\r
-               }\r
-       }\r
-       function toggleDisplay() {\r
-               td = document.getElementById('fontdisplay');\r
-               td.value = ( td.value == 'none' ) ? 'inline' : 'none';\r
-               kUpdate('fontdisplay');\r
-       }\r
-       function toggleAdvanced() {\r
-               a = document.getElementById('jsAdvanced');\r
-               if ( a.style.display == 'none' )\r
-                       a.style.display = 'block';\r
-               else\r
-                       a.style.display = 'none';\r
-       }\r
-       function kDefaults() {\r
-               document.getElementById('headerimage').value = '';\r
-               document.getElementById('advuppercolor').value = document.getElementById('uppercolor').value = '#69aee7';\r
-               document.getElementById('advlowercolor').value = document.getElementById('lowercolor').value = '#4180b6';\r
-               document.getElementById('header').style.background = 'url("<?php echo get_template_directory_uri(); ?>/images/kubrickheader.jpg") center no-repeat';\r
-               document.getElementById('header').style.color = '#FFFFFF';\r
-               document.getElementById('advfontcolor').value = document.getElementById('fontcolor').value = '';\r
-               document.getElementById('fontdisplay').value = 'inline';\r
-               document.getElementById('headerimg').style.display = document.getElementById('fontdisplay').value;\r
-       }\r
-       function kRevert() {\r
-               document.getElementById('headerimage').value = '<?php echo kubrick_header_image(); ?>';\r
-               document.getElementById('advuppercolor').value = document.getElementById('uppercolor').value = '#<?php echo kubrick_upper_color(); ?>';\r
-               document.getElementById('advlowercolor').value = document.getElementById('lowercolor').value = '#<?php echo kubrick_lower_color(); ?>';\r
-               document.getElementById('header').style.background = 'url("<?php echo kubrick_header_image_url(); ?>") center no-repeat';\r
-               document.getElementById('header').style.color = '';\r
-               document.getElementById('advfontcolor').value = document.getElementById('fontcolor').value = '<?php echo kubrick_header_color_string(); ?>';\r
-               document.getElementById('fontdisplay').value = '<?php echo kubrick_header_display_string(); ?>';\r
-               document.getElementById('headerimg').style.display = document.getElementById('fontdisplay').value;\r
-       }\r
-       function kInit() {\r
-               document.getElementById('jsForm').style.display = 'block';\r
-               document.getElementById('nonJsForm').style.display = 'none';\r
-       }\r
-       addLoadEvent(kInit);\r
-// ]]>\r
-</script>\r
-<style type='text/css'>\r
-       #headwrap {\r
-               text-align: center;\r
-       }\r
-       #kubrick-header {\r
-               font-size: 80%;\r
-       }\r
-       #kubrick-header .hibrowser {\r
-               width: 780px;\r
-               height: 260px;\r
-               overflow: scroll;\r
-       }\r
-       #kubrick-header #hitarget {\r
-               display: none;\r
-       }\r
-       #kubrick-header #header h1 {\r
-               font-family: 'Trebuchet MS', 'Lucida Grande', Verdana, Arial, Sans-Serif;\r
-               font-weight: bold;\r
-               font-size: 4em;\r
-               text-align: center;\r
-               padding-top: 70px;\r
-               margin: 0;\r
-       }\r
-\r
-       #kubrick-header #header .description {\r
-               font-family: 'Lucida Grande', Verdana, Arial, Sans-Serif;\r
-               font-size: 1.2em;\r
-               text-align: center;\r
-       }\r
-       #kubrick-header #header {\r
-               text-decoration: none;\r
-               color: <?php echo kubrick_header_color_string(); ?>;\r
-               padding: 0;\r
-               margin: 0;\r
-               height: 200px;\r
-               text-align: center;\r
-               background: url('<?php echo kubrick_header_image_url(); ?>') center no-repeat;\r
-       }\r
-       #kubrick-header #headerimg {\r
-               margin: 0;\r
-               height: 200px;\r
-               width: 100%;\r
-               display: <?php echo kubrick_header_display_string(); ?>;\r
-       }\r
-       #jsForm {\r
-               display: none;\r
-               text-align: center;\r
-       }\r
-       #jsForm input.submit, #jsForm input.button, #jsAdvanced input.button {\r
-               padding: 0px;\r
-               margin: 0px;\r
-       }\r
-       #advanced {\r
-               text-align: center;\r
-               width: 620px;\r
-       }\r
-       html>body #advanced {\r
-               text-align: center;\r
-               position: relative;\r
-               left: 50%;\r
-               margin-left: -380px;\r
-       }\r
-       #jsAdvanced {\r
-               text-align: right;\r
-       }\r
-       #nonJsForm {\r
-               position: relative;\r
-               text-align: left;\r
-               margin-left: -370px;\r
-               left: 50%;\r
-       }\r
-       #nonJsForm label {\r
-               padding-top: 6px;\r
-               padding-right: 5px;\r
-               float: left;\r
-               width: 100px;\r
-               text-align: right;\r
-       }\r
-       .defbutton {\r
-               font-weight: bold;\r
-       }\r
-       .zerosize {\r
-               width: 0px;\r
-               height: 0px;\r
-               overflow: hidden;\r
-       }\r
-       #colorPickerDiv a, #colorPickerDiv a:hover {\r
-               padding: 1px;\r
-               text-decoration: none;\r
-               border-bottom: 0px;\r
-       }\r
-</style>\r
-<?php\r
-}\r
-\r
-function kubrick_theme_page() {\r
-       if ( $_REQUEST['saved'] ) echo '<div id="message" class="updated fade"><p><strong>Options saved.</strong></p></div>';\r
-?>\r
-<div class='wrap'>\r
-       <div id="kubrick-header">\r
-               <h2>Header Image and Color</h2>\r
-               <div id="headwrap">\r
-                       <div id="header">\r
-                               <div id="headerimg">\r
-                                       <h1><?php bloginfo('name'); ?></h1>\r
-                                       <div class="description"><?php bloginfo('description'); ?></div>\r
-                               </div>\r
-                       </div>\r
-               </div>\r
-               <br />\r
-               <div id="nonJsForm">\r
-                       <form method="post" action="">\r
-                               <div class="zerosize"><input type="submit" name="defaultsubmit" value="Save" /></div>\r
-                               <label for="njfontcolor">Font Color:</label><input type="text" name="njfontcolor" id="njfontcolor" value="<?php echo kubrick_header_color(); ?>" /> Any CSS color (<code>red</code> or <code>#FF0000</code> or <code>rgb(255, 0, 0)</code>)<br />\r
-                               <label for="njuppercolor">Upper Color:</label><input type="text" name="njuppercolor" id="njuppercolor" value="#<?php echo kubrick_upper_color(); ?>" /> HEX only (<code>#FF0000</code> or <code>#F00</code>)<br />\r
-                               <label for="njlowercolor">Lower Color:</label><input type="text" name="njlowercolor" id="njlowercolor" value="#<?php echo kubrick_lower_color(); ?>" /> HEX only (<code>#FF0000</code> or <code>#F00</code>)<br />\r
-                               <input type="hidden" name="hi" id="hi" value="<?php echo kubrick_header_image(); ?>" />\r
-                               <input type="submit" name="toggledisplay" id="toggledisplay" value="Toggle Text" />\r
-                               <input type="submit" name="defaults" value="Use Defaults" />\r
-                               <input type="submit" class="defbutton" name="submitform" value="&nbsp;&nbsp;Save&nbsp;&nbsp;" />\r
-                               <input type="hidden" name="action" value="save" />\r
-                               <input type="hidden" name="njform" value="true" />\r
-                       </form>\r
-               </div>\r
-               <div id="jsForm">\r
-                       <form style="display:inline;" method="post" name="hicolor" id="hicolor" action="<?php echo $_SERVER['REQUEST_URI']; ?>">\r
-                               <input type="button" onclick="tgt=document.getElementById('fontcolor');colorSelect(tgt,'pick1');return false;" name="pick1" id="pick1" value="Font Color"></input>\r
-                               <input type="button" onclick="tgt=document.getElementById('uppercolor');colorSelect(tgt,'pick2');return false;" name="pick2" id="pick2" value="Upper Color"></input>\r
-                               <input type="button" onclick="tgt=document.getElementById('lowercolor');colorSelect(tgt,'pick3');return false;" name="pick3" id="pick3" value="Lower Color"></input>\r
-                               <input type="button" name="revert" value="Revert" onclick="kRevert()" />\r
-                               <input type="button" value="Advanced" onclick="toggleAdvanced()" />\r
-                               <input type="submit" name="submitform" class="defbutton" value="Save" onclick="cp.hidePopup('prettyplease')" />\r
-                               <input type="hidden" name="action" value="save" />\r
-                               <input type="hidden" name="fontdisplay" id="fontdisplay" value="<?php echo kubrick_header_display(); ?>" />\r
-                               <input type="hidden" name="fontcolor" id="fontcolor" value="<?php echo kubrick_header_color(); ?>" />\r
-                               <input type="hidden" name="uppercolor" id="uppercolor" value="<?php echo kubrick_upper_color(); ?>" />\r
-                               <input type="hidden" name="lowercolor" id="lowercolor" value="<?php echo kubrick_lower_color(); ?>" />\r
-                               <input type="hidden" name="headerimage" id="headerimage" value="<?php echo kubrick_header_image(); ?>" />\r
-                       </form>\r
-                       <div id="colorPickerDiv" style="z-index: 100;background:#eee;border:1px solid #ccc;position:absolute;visibility:hidden;"> </div>\r
-                       <div id="advanced">\r
-                               <form id="jsAdvanced" style="display:none;" action="">\r
-                                       <label for="advfontcolor">Font Color (CSS): </label><input type="text" id="advfontcolor" onchange="advUpdate(this.value, 'fontcolor')" value="<?php echo kubrick_header_color(); ?>" /><br />\r
-                                       <label for="advuppercolor">Upper Color (HEX): </label><input type="text" id="advuppercolor" onchange="advUpdate(this.value, 'uppercolor')" value="#<?php echo kubrick_upper_color(); ?>" /><br />\r
-                                       <label for="advlowercolor">Lower Color (HEX): </label><input type="text" id="advlowercolor" onchange="advUpdate(this.value, 'lowercolor')" value="#<?php echo kubrick_lower_color(); ?>" /><br />\r
-                                       <input type="button" name="default" value="Select Default Colors" onclick="kDefaults()" /><br />\r
-                                       <input type="button" onclick="toggleDisplay();return false;" name="pick" id="pick" value="Toggle Text Display"></input><br />\r
-                               </form>\r
-                       </div>\r
-               </div>\r
-       </div>\r
-</div>\r
-<?php } ?>\r
+<?php
+
+function kubrick_head() {
+       $head = "<style type='text/css'>\n<!--";
+       $output = '';
+       if ( kubrick_header_image() ) {
+               $url =  kubrick_header_image_url() ;
+               $output .= "#header { background: url('$url') no-repeat bottom center; }\n";
+       }
+       if ( false !== ( $color = kubrick_header_color() ) ) {
+               $output .= "#headerimg h1 a, #headerimg h1 a:visited, #headerimg .description { color: $color; }\n";
+       }
+       if ( false !== ( $display = kubrick_header_display() ) ) {
+               $output .= "#headerimg { display: $display }\n";
+       }
+       $foot = "--></style>\n";
+       if ( '' != $output )
+               echo $head . $output . $foot;
+}
+
+add_action('wp_head', 'kubrick_head');
+
+function kubrick_header_image() {
+       return apply_filters('kubrick_header_image', get_option('kubrick_header_image'));
+}
+
+function kubrick_upper_color() {
+       if (strpos($url = kubrick_header_image_url(), 'header-img.php?') !== false) {
+               parse_str(substr($url, strpos($url, '?') + 1), $q);
+               return $q['upper'];
+       } else
+               return '69aee7';
+}
+
+function kubrick_lower_color() {
+       if (strpos($url = kubrick_header_image_url(), 'header-img.php?') !== false) {
+               parse_str(substr($url, strpos($url, '?') + 1), $q);
+               return $q['lower'];
+       } else
+               return '4180b6';
+}
+
+function kubrick_header_image_url() {
+       if ( $image = kubrick_header_image() )
+               $url = get_template_directory_uri() . '/images/' . $image;
+       else
+               $url = get_template_directory_uri() . '/images/kubrickheader.jpg';
+
+       return $url;
+}
+
+function kubrick_header_color() {
+       return apply_filters('kubrick_header_color', get_option('kubrick_header_color'));
+}
+
+function kubrick_header_color_string() {
+       $color = kubrick_header_color();
+       if ( false === $color )
+               return 'white';
+
+       return $color;
+}
+
+function kubrick_header_display() {
+       return apply_filters('kubrick_header_display', get_option('kubrick_header_display'));
+}
+
+function kubrick_header_display_string() {
+       $display = kubrick_header_display();
+       return $display ? $display : 'inline';
+}
+
+add_action('admin_menu', 'kubrick_add_theme_page');
+
+function kubrick_add_theme_page() {
+       if ( $_GET['page'] == basename(__FILE__) ) {
+               if ( 'save' == $_REQUEST['action'] ) {
+                       check_admin_referer('kubrick-header');
+                       if ( isset($_REQUEST['njform']) ) {
+                               if ( isset($_REQUEST['defaults']) ) {
+                                       delete_option('kubrick_header_image');
+                                       delete_option('kubrick_header_color');
+                                       delete_option('kubrick_header_display');
+                               } else {
+                                       if ( '' == $_REQUEST['njfontcolor'] )
+                                               delete_option('kubrick_header_color');
+                                       else {
+                                               $fontcolor = preg_replace('/^.*(#[0-9a-fA-F]{6})?.*$/', '$1', $_REQUEST['njfontcolor']);
+                                               update_option('kubrick_header_color', $fontcolor);
+                                       }
+                                       if ( preg_match('/[0-9A-F]{6}|[0-9A-F]{3}/i', $_REQUEST['njuppercolor'], $uc) && preg_match('/[0-9A-F]{6}|[0-9A-F]{3}/i', $_REQUEST['njlowercolor'], $lc) ) {
+                                               $uc = ( strlen($uc[0]) == 3 ) ? $uc[0]{0}.$uc[0]{0}.$uc[0]{1}.$uc[0]{1}.$uc[0]{2}.$uc[0]{2} : $uc[0];
+                                               $lc = ( strlen($lc[0]) == 3 ) ? $lc[0]{0}.$lc[0]{0}.$lc[0]{1}.$lc[0]{1}.$lc[0]{2}.$lc[0]{2} : $lc[0];
+                                               update_option('kubrick_header_image', "header-img.php?upper=$uc&amp;lower=$lc");
+                                       }
+
+                                       if ( isset($_REQUEST['toggledisplay']) ) {
+                                               if ( false === get_option('kubrick_header_display') )
+                                                       update_option('kubrick_header_display', 'none');
+                                               else
+                                                       delete_option('kubrick_header_display');
+                                       }
+                               }
+                       } else {
+
+                               if ( isset($_REQUEST['headerimage']) ) {
+                                       check_admin_referer('kubrick-header');
+                                       if ( '' == $_REQUEST['headerimage'] )
+                                               delete_option('kubrick_header_image');
+                                       else {
+                                               $headerimage = preg_replace('/^.*?(header-img.php\?upper=[0-9a-fA-F]{6}&lower=[0-9a-fA-F]{6})?.*$/', '$1', $_REQUEST['headerimage']);
+                                               update_option('kubrick_header_image', $headerimage);
+                                       }
+                               }
+
+                               if ( isset($_REQUEST['fontcolor']) ) {
+                                       check_admin_referer('kubrick-header');
+                                       if ( '' == $_REQUEST['fontcolor'] )
+                                               delete_option('kubrick_header_color');
+                                       else {
+                                               $fontcolor = preg_replace('/^.*?(#[0-9a-fA-F]{6})?.*$/', '$1', $_REQUEST['fontcolor']);
+                                               update_option('kubrick_header_color', $fontcolor);
+                                       }
+                               }
+
+                               if ( isset($_REQUEST['fontdisplay']) ) {
+                                       check_admin_referer('kubrick-header');
+                                       if ( '' == $_REQUEST['fontdisplay'] || 'inline' == $_REQUEST['fontdisplay'] )
+                                               delete_option('kubrick_header_display');
+                                       else
+                                               update_option('kubrick_header_display', 'none');
+                               }
+                       }
+                       //print_r($_REQUEST);
+                       wp_redirect("themes.php?page=functions.php&saved=true");
+                       die;
+               }
+               add_action('admin_head', 'kubrick_theme_page_head');
+       }
+       add_theme_page('Customize Header', 'Header Image and Color', 'edit_themes', basename(__FILE__), 'kubrick_theme_page');
+}
+
+function kubrick_theme_page_head() {
+?>
+<script type="text/javascript" src="../wp-includes/js/colorpicker.js"></script>
+<script type='text/javascript'>
+// <![CDATA[
+       function pickColor(color) {
+               ColorPicker_targetInput.value = color;
+               kUpdate(ColorPicker_targetInput.id);
+       }
+       function PopupWindow_populate(contents) {
+               contents += '<br /><p style="text-align:center;margin-top:0px;"><input type="button" value="Close Color Picker" onclick="cp.hidePopup(\'prettyplease\')"></input></p>';
+               this.contents = contents;
+               this.populated = false;
+       }
+       function PopupWindow_hidePopup(magicword) {
+               if ( magicword != 'prettyplease' )
+                       return false;
+               if (this.divName != null) {
+                       if (this.use_gebi) {
+                               document.getElementById(this.divName).style.visibility = "hidden";
+                       }
+                       else if (this.use_css) {
+                               document.all[this.divName].style.visibility = "hidden";
+                       }
+                       else if (this.use_layers) {
+                               document.layers[this.divName].visibility = "hidden";
+                       }
+               }
+               else {
+                       if (this.popupWindow && !this.popupWindow.closed) {
+                               this.popupWindow.close();
+                               this.popupWindow = null;
+                       }
+               }
+               return false;
+       }
+       function colorSelect(t,p) {
+               if ( cp.p == p && document.getElementById(cp.divName).style.visibility != "hidden" )
+                       cp.hidePopup('prettyplease');
+               else {
+                       cp.p = p;
+                       cp.select(t,p);
+               }
+       }
+       function PopupWindow_setSize(width,height) {
+               this.width = 162;
+               this.height = 210;
+       }
+
+       var cp = new ColorPicker();
+       function advUpdate(val, obj) {
+               document.getElementById(obj).value = val;
+               kUpdate(obj);
+       }
+       function kUpdate(oid) {
+               if ( 'uppercolor' == oid || 'lowercolor' == oid ) {
+                       uc = document.getElementById('uppercolor').value.replace('#', '');
+                       lc = document.getElementById('lowercolor').value.replace('#', '');
+                       hi = document.getElementById('headerimage');
+                       hi.value = 'header-img.php?upper='+uc+'&lower='+lc;
+                       document.getElementById('header').style.background = 'url("<?php echo get_template_directory_uri(); ?>/images/'+hi.value+'") center no-repeat';
+                       document.getElementById('advuppercolor').value = '#'+uc;
+                       document.getElementById('advlowercolor').value = '#'+lc;
+               }
+               if ( 'fontcolor' == oid ) {
+                       document.getElementById('header').style.color = document.getElementById('fontcolor').value;
+                       document.getElementById('advfontcolor').value = document.getElementById('fontcolor').value;
+               }
+               if ( 'fontdisplay' == oid ) {
+                       document.getElementById('headerimg').style.display = document.getElementById('fontdisplay').value;
+               }
+       }
+       function toggleDisplay() {
+               td = document.getElementById('fontdisplay');
+               td.value = ( td.value == 'none' ) ? 'inline' : 'none';
+               kUpdate('fontdisplay');
+       }
+       function toggleAdvanced() {
+               a = document.getElementById('jsAdvanced');
+               if ( a.style.display == 'none' )
+                       a.style.display = 'block';
+               else
+                       a.style.display = 'none';
+       }
+       function kDefaults() {
+               document.getElementById('headerimage').value = '';
+               document.getElementById('advuppercolor').value = document.getElementById('uppercolor').value = '#69aee7';
+               document.getElementById('advlowercolor').value = document.getElementById('lowercolor').value = '#4180b6';
+               document.getElementById('header').style.background = 'url("<?php echo get_template_directory_uri(); ?>/images/kubrickheader.jpg") center no-repeat';
+               document.getElementById('header').style.color = '#FFFFFF';
+               document.getElementById('advfontcolor').value = document.getElementById('fontcolor').value = '';
+               document.getElementById('fontdisplay').value = 'inline';
+               document.getElementById('headerimg').style.display = document.getElementById('fontdisplay').value;
+       }
+       function kRevert() {
+               document.getElementById('headerimage').value = '<?php echo js_escape(kubrick_header_image()); ?>';
+               document.getElementById('advuppercolor').value = document.getElementById('uppercolor').value = '#<?php echo js_escape(kubrick_upper_color()); ?>';
+               document.getElementById('advlowercolor').value = document.getElementById('lowercolor').value = '#<?php echo js_escape(kubrick_lower_color()); ?>';
+               document.getElementById('header').style.background = 'url("<?php echo js_escape(kubrick_header_image_url()); ?>") center no-repeat';
+               document.getElementById('header').style.color = '';
+               document.getElementById('advfontcolor').value = document.getElementById('fontcolor').value = '<?php echo js_escape(kubrick_header_color_string()); ?>';
+               document.getElementById('fontdisplay').value = '<?php echo js_escape(kubrick_header_display_string()); ?>';
+               document.getElementById('headerimg').style.display = document.getElementById('fontdisplay').value;
+       }
+       function kInit() {
+               document.getElementById('jsForm').style.display = 'block';
+               document.getElementById('nonJsForm').style.display = 'none';
+       }
+       addLoadEvent(kInit);
+// ]]>
+</script>
+<style type='text/css'>
+       #headwrap {
+               text-align: center;
+       }
+       #kubrick-header {
+               font-size: 80%;
+       }
+       #kubrick-header .hibrowser {
+               width: 780px;
+               height: 260px;
+               overflow: scroll;
+       }
+       #kubrick-header #hitarget {
+               display: none;
+       }
+       #kubrick-header #header h1 {
+               font-family: 'Trebuchet MS', 'Lucida Grande', Verdana, Arial, Sans-Serif;
+               font-weight: bold;
+               font-size: 4em;
+               text-align: center;
+               padding-top: 70px;
+               margin: 0;
+       }
+
+       #kubrick-header #header .description {
+               font-family: 'Lucida Grande', Verdana, Arial, Sans-Serif;
+               font-size: 1.2em;
+               text-align: center;
+       }
+       #kubrick-header #header {
+               text-decoration: none;
+               color: <?php echo kubrick_header_color_string(); ?>;
+               padding: 0;
+               margin: 0;
+               height: 200px;
+               text-align: center;
+               background: url('<?php echo kubrick_header_image_url(); ?>') center no-repeat;
+       }
+       #kubrick-header #headerimg {
+               margin: 0;
+               height: 200px;
+               width: 100%;
+               display: <?php echo kubrick_header_display_string(); ?>;
+       }
+       #jsForm {
+               display: none;
+               text-align: center;
+       }
+       #jsForm input.submit, #jsForm input.button, #jsAdvanced input.button {
+               padding: 0px;
+               margin: 0px;
+       }
+       #advanced {
+               text-align: center;
+               width: 620px;
+       }
+       html>body #advanced {
+               text-align: center;
+               position: relative;
+               left: 50%;
+               margin-left: -380px;
+       }
+       #jsAdvanced {
+               text-align: right;
+       }
+       #nonJsForm {
+               position: relative;
+               text-align: left;
+               margin-left: -370px;
+               left: 50%;
+       }
+       #nonJsForm label {
+               padding-top: 6px;
+               padding-right: 5px;
+               float: left;
+               width: 100px;
+               text-align: right;
+       }
+       .defbutton {
+               font-weight: bold;
+       }
+       .zerosize {
+               width: 0px;
+               height: 0px;
+               overflow: hidden;
+       }
+       #colorPickerDiv a, #colorPickerDiv a:hover {
+               padding: 1px;
+               text-decoration: none;
+               border-bottom: 0px;
+       }
+</style>
+<?php
+}
+
+function kubrick_theme_page() {
+       if ( $_REQUEST['saved'] ) echo '<div id="message" class="updated fade"><p><strong>Options saved.</strong></p></div>';
+?>
+<div class='wrap'>
+       <div id="kubrick-header">
+               <h2>Header Image and Color</h2>
+               <div id="headwrap">
+                       <div id="header">
+                               <div id="headerimg">
+                                       <h1><?php bloginfo('name'); ?></h1>
+                                       <div class="description"><?php bloginfo('description'); ?></div>
+                               </div>
+                       </div>
+               </div>
+               <br />
+               <div id="nonJsForm">
+                       <form method="post" action="">
+                               <?php wp_nonce_field('kubrick-header'); ?>
+                               <div class="zerosize"><input type="submit" name="defaultsubmit" value="Save" /></div>
+                               <label for="njfontcolor">Font Color:</label><input type="text" name="njfontcolor" id="njfontcolor" value="<?php echo attribute_escape(kubrick_header_color()); ?>" /> Any CSS color (<code>red</code> or <code>#FF0000</code> or <code>rgb(255, 0, 0)</code>)<br />
+                               <label for="njuppercolor">Upper Color:</label><input type="text" name="njuppercolor" id="njuppercolor" value="#<?php echo attribute_escape(kubrick_upper_color()); ?>" /> HEX only (<code>#FF0000</code> or <code>#F00</code>)<br />
+                               <label for="njlowercolor">Lower Color:</label><input type="text" name="njlowercolor" id="njlowercolor" value="#<?php echo attribute_escape(kubrick_lower_color()); ?>" /> HEX only (<code>#FF0000</code> or <code>#F00</code>)<br />
+                               <input type="hidden" name="hi" id="hi" value="<?php echo attribute_escape(kubrick_header_image()); ?>" />
+                               <input type="submit" name="toggledisplay" id="toggledisplay" value="Toggle Text" />
+                               <input type="submit" name="defaults" value="Use Defaults" />
+                               <input type="submit" class="defbutton" name="submitform" value="&nbsp;&nbsp;Save&nbsp;&nbsp;" />
+                               <input type="hidden" name="action" value="save" />
+                               <input type="hidden" name="njform" value="true" />
+                       </form>
+               </div>
+               <div id="jsForm">
+                       <form style="display:inline;" method="post" name="hicolor" id="hicolor" action="<?php echo attribute_escape($_SERVER['REQUEST_URI']); ?>">
+                               <?php wp_nonce_field('kubrick-header'); ?>
+                               <input type="button" onclick="tgt=document.getElementById('fontcolor');colorSelect(tgt,'pick1');return false;" name="pick1" id="pick1" value="Font Color"></input>
+                               <input type="button" onclick="tgt=document.getElementById('uppercolor');colorSelect(tgt,'pick2');return false;" name="pick2" id="pick2" value="Upper Color"></input>
+                               <input type="button" onclick="tgt=document.getElementById('lowercolor');colorSelect(tgt,'pick3');return false;" name="pick3" id="pick3" value="Lower Color"></input>
+                               <input type="button" name="revert" value="Revert" onclick="kRevert()" />
+                               <input type="button" value="Advanced" onclick="toggleAdvanced()" />
+                               <input type="hidden" name="action" value="save" />
+                               <input type="hidden" name="fontdisplay" id="fontdisplay" value="<?php echo attribute_escape(kubrick_header_display()); ?>" />
+                               <input type="hidden" name="fontcolor" id="fontcolor" value="<?php echo attribute_escape(kubrick_header_color()); ?>" />
+                               <input type="hidden" name="uppercolor" id="uppercolor" value="<?php echo attribute_escape(kubrick_upper_color()); ?>" />
+                               <input type="hidden" name="lowercolor" id="lowercolor" value="<?php echo attribute_escape(kubrick_lower_color()); ?>" />
+                               <input type="hidden" name="headerimage" id="headerimage" value="<?php echo attribute_escape(kubrick_header_image()); ?>" />
+                               <p class="submit"><input type="submit" name="submitform" class="defbutton" value="<?php _e('Update Header &raquo;'); ?>" onclick="cp.hidePopup('prettyplease')" /></p>
+                       </form>
+                       <div id="colorPickerDiv" style="z-index: 100;background:#eee;border:1px solid #ccc;position:absolute;visibility:hidden;"> </div>
+                       <div id="advanced">
+                               <form id="jsAdvanced" style="display:none;" action="">
+                                       <?php wp_nonce_field('kubrick-header'); ?>
+                                       <label for="advfontcolor">Font Color (CSS): </label><input type="text" id="advfontcolor" onchange="advUpdate(this.value, 'fontcolor')" value="<?php echo attribute_escape(kubrick_header_color()); ?>" /><br />
+                                       <label for="advuppercolor">Upper Color (HEX): </label><input type="text" id="advuppercolor" onchange="advUpdate(this.value, 'uppercolor')" value="#<?php echo attribute_escape(kubrick_upper_color()); ?>" /><br />
+                                       <label for="advlowercolor">Lower Color (HEX): </label><input type="text" id="advlowercolor" onchange="advUpdate(this.value, 'lowercolor')" value="#<?php echo attribute_escape(kubrick_lower_color()); ?>" /><br />
+                                       <input type="button" name="default" value="Select Default Colors" onclick="kDefaults()" /><br />
+                                       <input type="button" onclick="toggleDisplay();return false;" name="pick" id="pick" value="Toggle Text Display"></input><br />
+                               </form>
+                       </div>
+               </div>
+       </div>
+</div>
+<?php } ?>