XPressME Integration Kit

Trac

source: wp-content/themes/toemon/functions.php @ 1

Last change on this file since 1 was 1, checked in by toemon, 15 years ago

取り敢えずインストールと表示が出来るようにした初期バージョン

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