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