| 10 | | function kubrick_head() { |
| 11 | | $head = "<style type='text/css'>\n<!--"; |
| 12 | | $output = ''; |
| 13 | | if ( kubrick_header_image() ) { |
| 14 | | $url = kubrick_header_image_url() ; |
| 15 | | $output .= "#header { background: url('$url') no-repeat bottom center; }\n"; |
| 16 | | } |
| 17 | | if ( false !== ( $color = kubrick_header_color() ) ) { |
| 18 | | $output .= "#headerimg h1 a, #headerimg h1 a:visited, #headerimg .description { color: $color; }\n"; |
| 19 | | } |
| 20 | | if ( false !== ( $display = kubrick_header_display() ) ) { |
| 21 | | $output .= "#headerimg { display: $display }\n"; |
| 22 | | } |
| 23 | | $foot = "--></style>\n"; |
| 24 | | if ( '' != $output ) |
| 25 | | echo $head . $output . $foot; |
| 26 | | } |
| | 10 | define('HEADER_TEXTCOLOR', 'white'); |
| | 11 | define('HEADER_IMAGE', '%s/images/kubrickheader.jpg'); // %s is theme dir uri |
| | 12 | define('HEADER_IMAGE_WIDTH', 760); |
| | 13 | define('HEADER_IMAGE_HEIGHT', 200); |
| 42 | | function kubrick_lower_color() { |
| 43 | | if (strpos($url = kubrick_header_image_url(), 'header-img.php?') !== false) { |
| 44 | | parse_str(substr($url, strpos($url, '?') + 1), $q); |
| 45 | | return $q['lower']; |
| 46 | | } else |
| 47 | | return '4180b6'; |
| 48 | | } |
| 49 | | |
| 50 | | function kubrick_header_image_url() { |
| 51 | | if ( $image = kubrick_header_image() ) |
| 52 | | $url = get_template_directory_uri() . '/images/' . $image; |
| 53 | | else |
| 54 | | $url = get_template_directory_uri() . '/images/kubrickheader.jpg'; |
| 55 | | |
| 56 | | return $url; |
| 57 | | } |
| 58 | | |
| 59 | | function kubrick_header_color() { |
| 60 | | return apply_filters('kubrick_header_color', get_option('kubrick_header_color')); |
| 61 | | } |
| 62 | | |
| 63 | | function kubrick_header_color_string() { |
| 64 | | $color = kubrick_header_color(); |
| 65 | | if ( false === $color ) |
| 66 | | return 'white'; |
| 67 | | |
| 68 | | return $color; |
| 69 | | } |
| 70 | | |
| 71 | | function kubrick_header_display() { |
| 72 | | return apply_filters('kubrick_header_display', get_option('kubrick_header_display')); |
| 73 | | } |
| 74 | | |
| 75 | | function kubrick_header_display_string() { |
| 76 | | $display = kubrick_header_display(); |
| 77 | | return $display ? $display : 'inline'; |
| 78 | | } |
| 79 | | |
| 80 | | add_action('admin_menu', 'kubrick_add_theme_page'); |
| 81 | | |
| 82 | | function kubrick_add_theme_page() { |
| 83 | | if ( $_GET['page'] == basename(__FILE__) ) { |
| 84 | | if ( 'save' == $_REQUEST['action'] ) { |
| 85 | | if ( isset($_REQUEST['njform']) ) { |
| 86 | | if ( isset($_REQUEST['defaults']) ) { |
| 87 | | delete_option('kubrick_header_image'); |
| 88 | | delete_option('kubrick_header_color'); |
| 89 | | delete_option('kubrick_header_display'); |
| 90 | | } else { |
| 91 | | if ( '' == $_REQUEST['njfontcolor'] ) |
| 92 | | delete_option('kubrick_header_color'); |
| 93 | | else |
| 94 | | update_option('kubrick_header_color', $_REQUEST['njfontcolor']); |
| 95 | | |
| 96 | | 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) ) { |
| 97 | | $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]; |
| 98 | | $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]; |
| 99 | | update_option('kubrick_header_image', "header-img.php?upper=$uc&lower=$lc"); |
| 100 | | } |
| 101 | | |
| 102 | | if ( isset($_REQUEST['toggledisplay']) ) { |
| 103 | | if ( false === get_option('kubrick_header_display') ) |
| 104 | | update_option('kubrick_header_display', 'none'); |
| 105 | | else |
| 106 | | delete_option('kubrick_header_display'); |
| 107 | | } |
| 108 | | } |
| 109 | | } else { |
| 110 | | |
| 111 | | if ( isset($_REQUEST['headerimage']) ) { |
| 112 | | if ( '' == $_REQUEST['headerimage'] ) |
| 113 | | delete_option('kubrick_header_image'); |
| 114 | | else |
| 115 | | update_option('kubrick_header_image', $_REQUEST['headerimage']); |
| 116 | | } |
| 117 | | |
| 118 | | if ( isset($_REQUEST['fontcolor']) ) { |
| 119 | | if ( '' == $_REQUEST['fontcolor'] ) |
| 120 | | delete_option('kubrick_header_color'); |
| 121 | | else |
| 122 | | update_option('kubrick_header_color', $_REQUEST['fontcolor']); |
| 123 | | } |
| 124 | | |
| 125 | | if ( isset($_REQUEST['fontdisplay']) ) { |
| 126 | | if ( '' == $_REQUEST['fontdisplay'] || 'inline' == $_REQUEST['fontdisplay'] ) |
| 127 | | delete_option('kubrick_header_display'); |
| 128 | | else |
| 129 | | update_option('kubrick_header_display', 'none'); |
| 130 | | } |
| 131 | | } |
| 132 | | //print_r($_REQUEST); |
| 133 | | wp_redirect("themes.php?page=functions.php&saved=true"); |
| 134 | | die; |
| 135 | | } |
| 136 | | add_action('admin_head', 'kubrick_theme_page_head'); |
| 137 | | } |
| 138 | | add_theme_page('Customize Header', 'Header Image and Color', 'edit_themes', basename(__FILE__), 'kubrick_theme_page'); |
| 139 | | } |
| 140 | | |
| 141 | | function kubrick_theme_page_head() { |
| | 31 | function kubrick_admin_header_style() { |
| 143 | | <script type="text/javascript" src="../wp-includes/js/colorpicker.js"></script> |
| 144 | | <script type='text/javascript'> |
| 145 | | // <![CDATA[ |
| 146 | | function pickColor(color) { |
| 147 | | ColorPicker_targetInput.value = color; |
| 148 | | kUpdate(ColorPicker_targetInput.id); |
| 149 | | } |
| 150 | | function PopupWindow_populate(contents) { |
| 151 | | contents += '<br /><p style="text-align:center;margin-top:0px;"><input type="button" value="Close Color Picker" onclick="cp.hidePopup(\'prettyplease\')"></input></p>'; |
| 152 | | this.contents = contents; |
| 153 | | this.populated = false; |
| 154 | | } |
| 155 | | function PopupWindow_hidePopup(magicword) { |
| 156 | | if ( magicword != 'prettyplease' ) |
| 157 | | return false; |
| 158 | | if (this.divName != null) { |
| 159 | | if (this.use_gebi) { |
| 160 | | document.getElementById(this.divName).style.visibility = "hidden"; |
| 161 | | } |
| 162 | | else if (this.use_css) { |
| 163 | | document.all[this.divName].style.visibility = "hidden"; |
| 164 | | } |
| 165 | | else if (this.use_layers) { |
| 166 | | document.layers[this.divName].visibility = "hidden"; |
| 167 | | } |
| 168 | | } |
| 169 | | else { |
| 170 | | if (this.popupWindow && !this.popupWindow.closed) { |
| 171 | | this.popupWindow.close(); |
| 172 | | this.popupWindow = null; |
| 173 | | } |
| 174 | | } |
| 175 | | return false; |
| 176 | | } |
| 177 | | function colorSelect(t,p) { |
| 178 | | if ( cp.p == p && document.getElementById(cp.divName).style.visibility != "hidden" ) |
| 179 | | cp.hidePopup('prettyplease'); |
| 180 | | else { |
| 181 | | cp.p = p; |
| 182 | | cp.select(t,p); |
| 183 | | } |
| 184 | | } |
| 185 | | function PopupWindow_setSize(width,height) { |
| 186 | | this.width = 162; |
| 187 | | this.height = 210; |
| 188 | | } |
| 189 | | |
| 190 | | var cp = new ColorPicker(); |
| 191 | | function advUpdate(val, obj) { |
| 192 | | document.getElementById(obj).value = val; |
| 193 | | kUpdate(obj); |
| 194 | | } |
| 195 | | function kUpdate(oid) { |
| 196 | | if ( 'uppercolor' == oid || 'lowercolor' == oid ) { |
| 197 | | uc = document.getElementById('uppercolor').value.replace('#', ''); |
| 198 | | lc = document.getElementById('lowercolor').value.replace('#', ''); |
| 199 | | hi = document.getElementById('headerimage'); |
| 200 | | hi.value = 'header-img.php?upper='+uc+'&lower='+lc; |
| 201 | | document.getElementById('header').style.background = 'url("<?php echo get_template_directory_uri(); ?>/images/'+hi.value+'") center no-repeat'; |
| 202 | | document.getElementById('advuppercolor').value = '#'+uc; |
| 203 | | document.getElementById('advlowercolor').value = '#'+lc; |
| 204 | | } |
| 205 | | if ( 'fontcolor' == oid ) { |
| 206 | | document.getElementById('header').style.color = document.getElementById('fontcolor').value; |
| 207 | | document.getElementById('advfontcolor').value = document.getElementById('fontcolor').value; |
| 208 | | } |
| 209 | | if ( 'fontdisplay' == oid ) { |
| 210 | | document.getElementById('headerimg').style.display = document.getElementById('fontdisplay').value; |
| 211 | | } |
| 212 | | } |
| 213 | | function toggleDisplay() { |
| 214 | | td = document.getElementById('fontdisplay'); |
| 215 | | td.value = ( td.value == 'none' ) ? 'inline' : 'none'; |
| 216 | | kUpdate('fontdisplay'); |
| 217 | | } |
| 218 | | function toggleAdvanced() { |
| 219 | | a = document.getElementById('jsAdvanced'); |
| 220 | | if ( a.style.display == 'none' ) |
| 221 | | a.style.display = 'block'; |
| 222 | | else |
| 223 | | a.style.display = 'none'; |
| 224 | | } |
| 225 | | function kDefaults() { |
| 226 | | document.getElementById('headerimage').value = ''; |
| 227 | | document.getElementById('advuppercolor').value = document.getElementById('uppercolor').value = '#69aee7'; |
| 228 | | document.getElementById('advlowercolor').value = document.getElementById('lowercolor').value = '#4180b6'; |
| 229 | | document.getElementById('header').style.background = 'url("<?php echo get_template_directory_uri(); ?>/images/kubrickheader.jpg") center no-repeat'; |
| 230 | | document.getElementById('header').style.color = '#FFFFFF'; |
| 231 | | document.getElementById('advfontcolor').value = document.getElementById('fontcolor').value = ''; |
| 232 | | document.getElementById('fontdisplay').value = 'inline'; |
| 233 | | document.getElementById('headerimg').style.display = document.getElementById('fontdisplay').value; |
| 234 | | } |
| 235 | | function kRevert() { |
| 236 | | document.getElementById('headerimage').value = '<?php echo kubrick_header_image(); ?>'; |
| 237 | | document.getElementById('advuppercolor').value = document.getElementById('uppercolor').value = '#<?php echo kubrick_upper_color(); ?>'; |
| 238 | | document.getElementById('advlowercolor').value = document.getElementById('lowercolor').value = '#<?php echo kubrick_lower_color(); ?>'; |
| 239 | | document.getElementById('header').style.background = 'url("<?php echo kubrick_header_image_url(); ?>") center no-repeat'; |
| 240 | | document.getElementById('header').style.color = ''; |
| 241 | | document.getElementById('advfontcolor').value = document.getElementById('fontcolor').value = '<?php echo kubrick_header_color_string(); ?>'; |
| 242 | | document.getElementById('fontdisplay').value = '<?php echo kubrick_header_display_string(); ?>'; |
| 243 | | document.getElementById('headerimg').style.display = document.getElementById('fontdisplay').value; |
| 244 | | } |
| 245 | | function kInit() { |
| 246 | | document.getElementById('jsForm').style.display = 'block'; |
| 247 | | document.getElementById('nonJsForm').style.display = 'none'; |
| 248 | | } |
| 249 | | addLoadEvent(kInit); |
| 250 | | // ]]> |
| 251 | | </script> |
| 350 | | <div class='wrap'> |
| 351 | | <div id="kubrick-header"> |
| 352 | | <h2>Header Image and Color</h2> |
| 353 | | <div id="headwrap"> |
| 354 | | <div id="header"> |
| 355 | | <div id="headerimg"> |
| 356 | | <h1><?php bloginfo('name'); ?></h1> |
| 357 | | <div class="description"><?php bloginfo('description'); ?></div> |
| 358 | | </div> |
| 359 | | </div> |
| 360 | | </div> |
| 361 | | <br /> |
| 362 | | <div id="nonJsForm"> |
| 363 | | <form method="post" action=""> |
| 364 | | <div class="zerosize"><input type="submit" name="defaultsubmit" value="Save" /></div> |
| 365 | | <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 /> |
| 366 | | <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 /> |
| 367 | | <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 /> |
| 368 | | <input type="hidden" name="hi" id="hi" value="<?php echo kubrick_header_image(); ?>" /> |
| 369 | | <input type="submit" name="toggledisplay" id="toggledisplay" value="Toggle Text" /> |
| 370 | | <input type="submit" name="defaults" value="Use Defaults" /> |
| 371 | | <input type="submit" class="defbutton" name="submitform" value=" Save " /> |
| 372 | | <input type="hidden" name="action" value="save" /> |
| 373 | | <input type="hidden" name="njform" value="true" /> |
| 374 | | </form> |
| 375 | | </div> |
| 376 | | <div id="jsForm"> |
| 377 | | <form style="display:inline;" method="post" name="hicolor" id="hicolor" action="<?php echo $_SERVER['REQUEST_URI']; ?>"> |
| 378 | | <input type="button" onclick="tgt=document.getElementById('fontcolor');colorSelect(tgt,'pick1');return false;" name="pick1" id="pick1" value="Font Color"></input> |
| 379 | | <input type="button" onclick="tgt=document.getElementById('uppercolor');colorSelect(tgt,'pick2');return false;" name="pick2" id="pick2" value="Upper Color"></input> |
| 380 | | <input type="button" onclick="tgt=document.getElementById('lowercolor');colorSelect(tgt,'pick3');return false;" name="pick3" id="pick3" value="Lower Color"></input> |
| 381 | | <input type="button" name="revert" value="Revert" onclick="kRevert()" /> |
| 382 | | <input type="button" value="Advanced" onclick="toggleAdvanced()" /> |
| 383 | | <input type="hidden" name="action" value="save" /> |
| 384 | | <input type="hidden" name="fontdisplay" id="fontdisplay" value="<?php echo kubrick_header_display(); ?>" /> |
| 385 | | <input type="hidden" name="fontcolor" id="fontcolor" value="<?php echo kubrick_header_color(); ?>" /> |
| 386 | | <input type="hidden" name="uppercolor" id="uppercolor" value="<?php echo kubrick_upper_color(); ?>" /> |
| 387 | | <input type="hidden" name="lowercolor" id="lowercolor" value="<?php echo kubrick_lower_color(); ?>" /> |
| 388 | | <input type="hidden" name="headerimage" id="headerimage" value="<?php echo kubrick_header_image(); ?>" /> |
| 389 | | <p class="submit"><input type="submit" name="submitform" class="defbutton" value="<?php _e('Update Header »'); ?>" onclick="cp.hidePopup('prettyplease')" /></p> |
| 390 | | </form> |
| 391 | | <div id="colorPickerDiv" style="z-index: 100;background:#eee;border:1px solid #ccc;position:absolute;visibility:hidden;"> </div> |
| 392 | | <div id="advanced"> |
| 393 | | <form id="jsAdvanced" style="display:none;" action=""> |
| 394 | | <label for="advfontcolor">Font Color (CSS): </label><input type="text" id="advfontcolor" onchange="advUpdate(this.value, 'fontcolor')" value="<?php echo kubrick_header_color(); ?>" /><br /> |
| 395 | | <label for="advuppercolor">Upper Color (HEX): </label><input type="text" id="advuppercolor" onchange="advUpdate(this.value, 'uppercolor')" value="#<?php echo kubrick_upper_color(); ?>" /><br /> |
| 396 | | <label for="advlowercolor">Lower Color (HEX): </label><input type="text" id="advlowercolor" onchange="advUpdate(this.value, 'lowercolor')" value="#<?php echo kubrick_lower_color(); ?>" /><br /> |
| 397 | | <input type="button" name="default" value="Select Default Colors" onclick="kDefaults()" /><br /> |
| 398 | | <input type="button" onclick="toggleDisplay();return false;" name="pick" id="pick" value="Toggle Text Display"></input><br /> |
| 399 | | </form> |
| 400 | | </div> |
| 401 | | </div> |
| 402 | | </div> |
| 403 | | </div> |
| 404 | | <?php } ?> |