Make WordPress Core

Ticket #9929: functions.php

File functions.php, 17.1 KB (added by jmulley, 17 years ago)

Fixed page

Line 
1<?php
2/**
3 * @package WordPress
4 * @subpackage Default_Theme
5 */
6
7automatic_feed_links();
8
9if ( function_exists('register_sidebar') ) {
10 register_sidebar(array(
11 'before_widget' => '<li id="%1$s" class="widget %2$s">',
12 'after_widget' => '</li>',
13 'before_title' => '<h2 class="widgettitle">',
14 'after_title' => '</h2>',
15 ));
16}
17
18/** @ignore */
19function kubrick_head() {
20 $head = "<style type='text/css'>\n<!--";
21 $output = '';
22 if ( kubrick_header_image() ) {
23 $url = kubrick_header_image_url() ;
24 $output .= "#header { background: url('$url') no-repeat bottom center; }\n";
25 }
26 if ( false !== ( $color = kubrick_header_color() ) ) {
27 $output .= "#headerimg h1 a, #headerimg h1 a:visited, #headerimg .description { color: $color; }\n";
28 }
29 if ( false !== ( $display = kubrick_header_display() ) ) {
30 $output .= "#headerimg { display: $display }\n";
31 }
32 $foot = "--></style>\n";
33 if ( '' != $output )
34 echo $head . $output . $foot;
35}
36
37add_action('wp_head', 'kubrick_head');
38
39function kubrick_header_image() {
40 return apply_filters('kubrick_header_image', get_option('kubrick_header_image'));
41}
42
43function kubrick_upper_color() {
44 if (strpos($url = kubrick_header_image_url(), 'header-img.php?') !== false) {
45 parse_str(substr($url, strpos($url, '?') + 1), $q);
46 return $q['upper'];
47 } else
48 return '69aee7';
49}
50
51function kubrick_lower_color() {
52 if (strpos($url = kubrick_header_image_url(), 'header-img.php?') !== false) {
53 parse_str(substr($url, strpos($url, '?') + 1), $q);
54 return $q['lower'];
55 } else
56 return '4180b6';
57}
58
59function kubrick_header_image_url() {
60 if ( $image = kubrick_header_image() )
61 $url = get_template_directory_uri() . '/images/' . $image;
62 else
63 $url = get_template_directory_uri() . '/images/kubrickheader.jpg';
64
65 return $url;
66}
67
68function kubrick_header_color() {
69 return apply_filters('kubrick_header_color', get_option('kubrick_header_color'));
70}
71
72function kubrick_header_color_string() {
73 $color = kubrick_header_color();
74 if ( false === $color )
75 return 'white';
76
77 return $color;
78}
79
80function kubrick_header_display() {
81 return apply_filters('kubrick_header_display', get_option('kubrick_header_display'));
82}
83
84function kubrick_header_display_string() {
85 $display = kubrick_header_display();
86 return $display ? $display : 'inline';
87}
88
89add_action('admin_menu', 'kubrick_add_theme_page');
90
91function kubrick_add_theme_page() {
92 if ( isset( $_GET['page'] ) && $_GET['page'] == basename(__FILE__) ) {
93 if ( isset( $_REQUEST['action'] ) && 'save' == $_REQUEST['action'] ) {
94 check_admin_referer('kubrick-header');
95 if ( isset($_REQUEST['njform']) ) {
96 if ( isset($_REQUEST['defaults']) ) {
97 delete_option('kubrick_header_image');
98 delete_option('kubrick_header_color');
99 delete_option('kubrick_header_display');
100 } else {
101 if ( '' == $_REQUEST['njfontcolor'] )
102 delete_option('kubrick_header_color');
103 else {
104 $fontcolor = preg_replace('/^.*(#[0-9a-fA-F]{6})?.*$/', '$1', $_REQUEST['njfontcolor']);
105 update_option('kubrick_header_color', $fontcolor);
106 }
107 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) ) {
108 $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];
109 $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];
110 update_option('kubrick_header_image', "header-img.php?upper=$uc&lower=$lc");
111 }
112
113 if ( isset($_REQUEST['toggledisplay']) ) {
114 if ( false === get_option('kubrick_header_display') )
115 update_option('kubrick_header_display', 'none');
116 else
117 delete_option('kubrick_header_display');
118 }
119 }
120 } else {
121
122 if ( isset($_REQUEST['headerimage']) ) {
123 check_admin_referer('kubrick-header');
124 if ( '' == $_REQUEST['headerimage'] )
125 delete_option('kubrick_header_image');
126 else {
127 $headerimage = preg_replace('/^.*?(header-img.php\?upper=[0-9a-fA-F]{6}&lower=[0-9a-fA-F]{6})?.*$/', '$1', $_REQUEST['headerimage']);
128 update_option('kubrick_header_image', $headerimage);
129 }
130 }
131
132 if ( isset($_REQUEST['fontcolor']) ) {
133 check_admin_referer('kubrick-header');
134 if ( '' == $_REQUEST['fontcolor'] )
135 delete_option('kubrick_header_color');
136 else {
137 $fontcolor = preg_replace('/^.*?(#[0-9a-fA-F]{6})?.*$/', '$1', $_REQUEST['fontcolor']);
138 update_option('kubrick_header_color', $fontcolor);
139 }
140 }
141
142 if ( isset($_REQUEST['fontdisplay']) ) {
143 check_admin_referer('kubrick-header');
144 if ( '' == $_REQUEST['fontdisplay'] || 'inline' == $_REQUEST['fontdisplay'] )
145 delete_option('kubrick_header_display');
146 else
147 update_option('kubrick_header_display', 'none');
148 }
149 }
150 //print_r($_REQUEST);
151 wp_redirect("themes.php?page=functions.php&saved=true");
152 die;
153 }
154 add_action('admin_head', 'kubrick_theme_page_head');
155 }
156 add_theme_page(__('Custom Header'), __('Custom Header'), 'edit_themes', basename(__FILE__), 'kubrick_theme_page');
157}
158
159function kubrick_theme_page_head() {
160?>
161<script type="text/javascript" src="../wp-includes/js/colorpicker.js"></script>
162<script type='text/javascript'>
163// <![CDATA[
164 function pickColor(color) {
165 ColorPicker_targetInput.value = color;
166 kUpdate(ColorPicker_targetInput.id);
167 }
168 function PopupWindow_populate(contents) {
169 contents += '<br /><p style="text-align:center;margin-top:0px;"><input type="button" class="button-secondary" value="<?php esc_attr_e('Close Color Picker'); ?>" onclick="cp.hidePopup(\'prettyplease\')"></input></p>';
170 this.contents = contents;
171 this.populated = false;
172 }
173 function PopupWindow_hidePopup(magicword) {
174 if ( magicword != 'prettyplease' )
175 return false;
176 if (this.divName != null) {
177 if (this.use_gebi) {
178 document.getElementById(this.divName).style.visibility = "hidden";
179 }
180 else if (this.use_css) {
181 document.all[this.divName].style.visibility = "hidden";
182 }
183 else if (this.use_layers) {
184 document.layers[this.divName].visibility = "hidden";
185 }
186 }
187 else {
188 if (this.popupWindow && !this.popupWindow.closed) {
189 this.popupWindow.close();
190 this.popupWindow = null;
191 }
192 }
193 return false;
194 }
195 function colorSelect(t,p) {
196 if ( cp.p == p && document.getElementById(cp.divName).style.visibility != "hidden" )
197 cp.hidePopup('prettyplease');
198 else {
199 cp.p = p;
200 cp.select(t,p);
201 }
202 }
203 function PopupWindow_setSize(width,height) {
204 this.width = 162;
205 this.height = 210;
206 }
207
208 var cp = new ColorPicker();
209 function advUpdate(val, obj) {
210 document.getElementById(obj).value = val;
211 kUpdate(obj);
212 }
213 function kUpdate(oid) {
214 if ( 'uppercolor' == oid || 'lowercolor' == oid ) {
215 uc = document.getElementById('uppercolor').value.replace('#', '');
216 lc = document.getElementById('lowercolor').value.replace('#', '');
217 hi = document.getElementById('headerimage');
218 hi.value = 'header-img.php?upper='+uc+'&lower='+lc;
219 document.getElementById('header').style.background = 'url("<?php echo get_template_directory_uri(); ?>/images/'+hi.value+'") center no-repeat';
220 document.getElementById('advuppercolor').value = '#'+uc;
221 document.getElementById('advlowercolor').value = '#'+lc;
222 }
223 if ( 'fontcolor' == oid ) {
224 document.getElementById('header').style.color = document.getElementById('fontcolor').value;
225 document.getElementById('advfontcolor').value = document.getElementById('fontcolor').value;
226 }
227 if ( 'fontdisplay' == oid ) {
228 document.getElementById('headerimg').style.display = document.getElementById('fontdisplay').value;
229 }
230 }
231 function toggleDisplay() {
232 td = document.getElementById('fontdisplay');
233 td.value = ( td.value == 'none' ) ? 'inline' : 'none';
234 kUpdate('fontdisplay');
235 }
236 function toggleAdvanced() {
237 a = document.getElementById('jsAdvanced');
238 if ( a.style.display == 'none' )
239 a.style.display = 'block';
240 else
241 a.style.display = 'none';
242 }
243 function kDefaults() {
244 document.getElementById('headerimage').value = '';
245 document.getElementById('advuppercolor').value = document.getElementById('uppercolor').value = '#69aee7';
246 document.getElementById('advlowercolor').value = document.getElementById('lowercolor').value = '#4180b6';
247 document.getElementById('header').style.background = 'url("<?php echo get_template_directory_uri(); ?>/images/kubrickheader.jpg") center no-repeat';
248 document.getElementById('header').style.color = '#FFFFFF';
249 document.getElementById('advfontcolor').value = document.getElementById('fontcolor').value = '';
250 document.getElementById('fontdisplay').value = 'inline';
251 document.getElementById('headerimg').style.display = document.getElementById('fontdisplay').value;
252 }
253 function kRevert() {
254 document.getElementById('headerimage').value = '<?php echo esc_js(kubrick_header_image()); ?>';
255 document.getElementById('advuppercolor').value = document.getElementById('uppercolor').value = '#<?php echo esc_js(kubrick_upper_color()); ?>';
256 document.getElementById('advlowercolor').value = document.getElementById('lowercolor').value = '#<?php echo esc_js(kubrick_lower_color()); ?>';
257 document.getElementById('header').style.background = 'url("<?php echo esc_js(kubrick_header_image_url()); ?>") center no-repeat';
258 document.getElementById('header').style.color = '';
259 document.getElementById('advfontcolor').value = document.getElementById('fontcolor').value = '<?php echo esc_js(kubrick_header_color_string()); ?>';
260 document.getElementById('fontdisplay').value = '<?php echo esc_js(kubrick_header_display_string()); ?>';
261 document.getElementById('headerimg').style.display = document.getElementById('fontdisplay').value;
262 }
263 function kInit() {
264 document.getElementById('jsForm').style.display = 'block';
265 document.getElementById('nonJsForm').style.display = 'none';
266 }
267 addLoadEvent(kInit);
268// ]]>
269</script>
270<style type='text/css'>
271 #headwrap {
272 text-align: center;
273 }
274 #kubrick-header {
275 font-size: 80%;
276 }
277 #kubrick-header .hibrowser {
278 width: 780px;
279 height: 260px;
280 overflow: scroll;
281 }
282 #kubrick-header #hitarget {
283 display: none;
284 }
285 #kubrick-header #header h1 {
286 font-family: 'Trebuchet MS', 'Lucida Grande', Verdana, Arial, Sans-Serif;
287 font-weight: bold;
288 font-size: 4em;
289 text-align: center;
290 padding-top: 70px;
291 margin: 0;
292 }
293
294 #kubrick-header #header .description {
295 font-family: 'Lucida Grande', Verdana, Arial, Sans-Serif;
296 font-size: 1.2em;
297 text-align: center;
298 }
299 #kubrick-header #header {
300 text-decoration: none;
301 color: <?php echo kubrick_header_color_string(); ?>;
302 padding: 0;
303 margin: 0;
304 height: 200px;
305 text-align: center;
306 background: url('<?php echo kubrick_header_image_url(); ?>') center no-repeat;
307 }
308 #kubrick-header #headerimg {
309 margin: 0;
310 height: 200px;
311 width: 100%;
312 display: <?php echo kubrick_header_display_string(); ?>;
313 }
314 .description {
315 margin-top: 16px;
316 color: #fff;
317 }
318 #jsForm {
319 display: none;
320 text-align: center;
321 }
322 #jsForm input.submit, #jsForm input.button, #jsAdvanced input.button {
323 padding: 0px;
324 margin: 0px;
325 }
326 #advanced {
327 text-align: center;
328 width: 620px;
329 }
330 html>body #advanced {
331 text-align: center;
332 position: relative;
333 left: 50%;
334 margin-left: -380px;
335 }
336 #jsAdvanced {
337 text-align: right;
338 }
339 #nonJsForm {
340 position: relative;
341 text-align: left;
342 margin-left: -370px;
343 left: 50%;
344 }
345 #nonJsForm label {
346 padding-top: 6px;
347 padding-right: 5px;
348 float: left;
349 width: 100px;
350 text-align: right;
351 }
352 .defbutton {
353 font-weight: bold;
354 }
355 .zerosize {
356 width: 0px;
357 height: 0px;
358 overflow: hidden;
359 }
360 #colorPickerDiv a, #colorPickerDiv a:hover {
361 padding: 1px;
362 text-decoration: none;
363 border-bottom: 0px;
364 }
365</style>
366<?php
367}
368
369function kubrick_theme_page() {
370 if ( isset( $_REQUEST['saved'] ) ) echo '<div id="message" class="updated fade"><p><strong>'.__('Options saved.').'</strong></p></div>';
371?>
372<div class='wrap'>
373 <h2><?php _e('Customize Header'); ?></h2>
374 <div id="kubrick-header">
375 <div id="headwrap">
376 <div id="header">
377 <div id="headerimg">
378 <h1><?php bloginfo('name'); ?></h1>
379 <div class="description"><?php bloginfo('description'); ?></div>
380 </div>
381 </div>
382 </div>
383 <br />
384 <div id="nonJsForm">
385 <form method="post" action="">
386 <?php wp_nonce_field('kubrick-header'); ?>
387 <div class="zerosize"><input type="submit" name="defaultsubmit" value="<?php esc_attr_e('Save'); ?>" /></div>
388 <label for="njfontcolor"><?php _e('Font Color:'); ?></label><input type="text" name="njfontcolor" id="njfontcolor" value="<?php echo esc_attr(kubrick_header_color()); ?>" /> <?php printf(__('Any CSS color (%s or %s or %s)'), '<code>red</code>', '<code>#FF0000</code>', '<code>rgb(255, 0, 0)</code>'); ?><br />
389 <label for="njuppercolor"><?php _e('Upper Color:'); ?></label><input type="text" name="njuppercolor" id="njuppercolor" value="#<?php echo esc_attr(kubrick_upper_color()); ?>" /> <?php printf(__('HEX only (%s or %s)'), '<code>#FF0000</code>', '<code>#F00</code>'); ?><br />
390 <label for="njlowercolor"><?php _e('Lower Color:'); ?></label><input type="text" name="njlowercolor" id="njlowercolor" value="#<?php echo esc_attr(kubrick_lower_color()); ?>" /> <?php printf(__('HEX only (%s or %s)'), '<code>#FF0000</code>', '<code>#F00</code>'); ?><br />
391 <input type="hidden" name="hi" id="hi" value="<?php echo esc_attr(kubrick_header_image()); ?>" />
392 <input type="submit" name="toggledisplay" id="toggledisplay" value="<?php esc_attr_e('Toggle Text'); ?>" />
393 <input type="submit" name="defaults" value="<?php esc_attr_e('Use Defaults'); ?>" />
394 <input type="submit" class="defbutton" name="submitform" value="&nbsp;&nbsp;<?php esc_attr_e('Save'); ?>&nbsp;&nbsp;" />
395 <input type="hidden" name="action" value="save" />
396 <input type="hidden" name="njform" value="true" />
397 </form>
398 </div>
399 <div id="jsForm">
400 <form style="display:inline;" method="post" name="hicolor" id="hicolor" action="<?php echo esc_attr($_SERVER['REQUEST_URI']); ?>">
401 <?php wp_nonce_field('kubrick-header'); ?>
402 <input type="button" class="button-secondary" onclick="tgt=document.getElementById('fontcolor');colorSelect(tgt,'pick1');return false;" name="pick1" id="pick1" value="<?php esc_attr_e('Font Color'); ?>"></input>
403 <input type="button" class="button-secondary" onclick="tgt=document.getElementById('uppercolor');colorSelect(tgt,'pick2');return false;" name="pick2" id="pick2" value="<?php esc_attr_e('Upper Color'); ?>"></input>
404 <input type="button" class="button-secondary" onclick="tgt=document.getElementById('lowercolor');colorSelect(tgt,'pick3');return false;" name="pick3" id="pick3" value="<?php esc_attr_e('Lower Color'); ?>"></input>
405 <input type="button" class="button-secondary" name="revert" value="<?php esc_attr_e('Revert'); ?>" onclick="kRevert()" />
406 <input type="button" class="button-secondary" value="<?php esc_attr_e('Advanced'); ?>" onclick="toggleAdvanced()" />
407 <input type="hidden" name="action" value="save" />
408 <input type="hidden" name="fontdisplay" id="fontdisplay" value="<?php echo esc_attr(kubrick_header_display()); ?>" />
409 <input type="hidden" name="fontcolor" id="fontcolor" value="<?php echo esc_attr(kubrick_header_color()); ?>" />
410 <input type="hidden" name="uppercolor" id="uppercolor" value="<?php echo esc_attr(kubrick_upper_color()); ?>" />
411 <input type="hidden" name="lowercolor" id="lowercolor" value="<?php echo esc_attr(kubrick_lower_color()); ?>" />
412 <input type="hidden" name="headerimage" id="headerimage" value="<?php echo esc_attr(kubrick_header_image()); ?>" />
413 <p class="submit"><input type="submit" name="submitform" class="button-primary" value="<?php esc_attr_e('Update Header'); ?>" onclick="cp.hidePopup('prettyplease')" /></p>
414 </form>
415 <div id="colorPickerDiv" style="z-index: 100;background:#eee;border:1px solid #ccc;position:absolute;visibility:hidden;"> </div>
416 <div id="advanced">
417 <form id="jsAdvanced" style="display:none;" action="">
418 <?php wp_nonce_field('kubrick-header'); ?>
419 <label for="advfontcolor"><?php _e('Font Color (CSS):'); ?> </label><input type="text" id="advfontcolor" onchange="advUpdate(this.value, 'fontcolor')" value="<?php echo esc_attr(kubrick_header_color()); ?>" /><br />
420 <label for="advuppercolor"><?php _e('Upper Color (HEX):');?> </label><input type="text" id="advuppercolor" onchange="advUpdate(this.value, 'uppercolor')" value="#<?php echo esc_attr(kubrick_upper_color()); ?>" /><br />
421 <label for="advlowercolor"><?php _e('Lower Color (HEX):'); ?> </label><input type="text" id="advlowercolor" onchange="advUpdate(this.value, 'lowercolor')" value="#<?php echo esc_attr(kubrick_lower_color()); ?>" /><br />
422 <input type="button" class="button-secondary" name="default" value="<?php esc_attr_e('Select Default Colors'); ?>" onclick="kDefaults()" /><br />
423 <input type="button" class="button-secondary" onclick="toggleDisplay();return false;" name="pick" id="pick" value="<?php esc_attr_e('Toggle Text Display'); ?>"></input><br />
424 </form>
425 </div>
426 </div>
427 </div>
428</div>
429<?php } ?>