Advertisement
NOXICON

Untitled

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