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