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