<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; }
#msg ul, pre { overflow: auto; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<title>[13403] trunk: Default header selector, first pass.</title>
</head>
<body>
<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/13403">13403</a></dd>
<dt>Author</dt> <dd>ryan</dd>
<dt>Date</dt> <dd>2010-02-25 19:18:44 +0000 (Thu, 25 Feb 2010)</dd>
</dl>
<h3>Log Message</h3>
<pre>Default header selector, first pass. see <a href="http://trac.wordpress.org/ticket/12343">#12343</a></pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadmincustomheaderphp">trunk/wp-admin/custom-header.php</a></li>
<li><a href="#trunkwpcontentthemestwentytenfunctionsphp">trunk/wp-content/themes/twentyten/functions.php</a></li>
<li><a href="#trunkwpincludesthemephp">trunk/wp-includes/theme.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadmincustomheaderphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/custom-header.php (13402 => 13403)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/custom-header.php        2010-02-25 17:10:00 UTC (rev 13402)
+++ trunk/wp-admin/custom-header.php        2010-02-25 19:18:44 UTC (rev 13403)
</span><span class="lines">@@ -33,6 +33,8 @@
</span><span class="cx">          */
</span><span class="cx">         var $admin_image_div_callback;
</span><span class="cx">
</span><ins>+        var $default_headers = array();
+
</ins><span class="cx">         /**
</span><span class="cx">          * PHP4 Constructor - Register administration header callback.
</span><span class="cx">          *
</span><span class="lines">@@ -133,9 +135,77 @@
</span><span class="cx">                         check_admin_referer('custom-header');
</span><span class="cx">                         remove_theme_mods();
</span><span class="cx">                 }
</span><ins>+
+                if ( isset($_POST['default-header']) ) {
+                        $this->process_default_headers();
+                        if ( isset($this->default_headers[$_POST['default-header']]) )
+                                set_theme_mod('header_image', esc_url($this->default_headers[$_POST['default-header']]['url']));
+                }
</ins><span class="cx">         }
</span><span class="cx">
</span><span class="cx">         /**
</span><ins>+         * Process the default headers
+         *
+         * @since 3.0.0
+         */
+        function process_default_headers() {
+                global $_wp_default_headers;
+
+                if ( !empty($this->headers) )
+                        return;
+
+                if ( !isset($_wp_default_headers) )
+                        return;
+
+                $this->default_headers = $_wp_default_headers;
+                foreach ( array_keys($this->default_headers) as $header ) {
+                        $this->default_headers[$header]['url'] = sprintf( $this->default_headers[$header]['url'], get_template_directory_uri(), get_stylesheet_directory_uri() );
+                        $this->default_headers[$header]['thumbnail_url'] = sprintf( $this->default_headers[$header]['thumbnail_url'], get_template_directory_uri(), get_stylesheet_directory_uri() );
+                }
+        }
+
+        /**
+         * Display UI for selecting one of several default headers.
+         *
+         * @since 3.0.0
+         */
+        function show_default_header_selector() {
+                echo '<table id="available-headers" cellspacing="0" cellpadding="0">';
+
+                $headers = array_keys($this->default_headers);
+                $table = array();
+                $rows = ceil(count($headers) / 3);
+                for ( $row = 1; $row <= $rows; $row++ ) {
+                        for ( $col = 1; $col <= 3; $col++ ) {
+                                $table[$row][$col] = array_shift($headers);
+                        }
+                }
+
+                foreach ( $table as $row => $cols ) {
+                        echo '<tr>';
+                        foreach ( $cols as $col => $header_key ) {
+                                if ( !$header_key )
+                                        continue;
+                                $class = array('available-theme');
+                                if ( $row == 1 ) $class[] = 'top';
+                                if ( $col == 1 ) $class[] = 'left';
+                                if ( $row == $rows ) $class[] = 'bottom';
+                                if ( $col == 3 ) $class[] = 'right';
+                                if ( !isset($this->headers[$header_key]))
+                                echo '<td class="' . join(' ', $class) . '">';
+                                $header_thumbnail = $this->default_headers[$header_key]['thumbnail_url'];
+                                $header_url = $this->default_headers[$header_key]['url'];
+                                $header_desc = $this->default_headers[$header_key]['description'];
+                                echo '<label><input name="default-header" type="radio" value="' . esc_attr($header_key) . '" ' . checked($header_url, get_header_image(), false) . ' />';
+                                echo '<img src="' . $header_thumbnail . '" alt="' . esc_attr($header_desc) .'" /></label>';
+                                echo '</td>';
+                        }
+                        echo '</tr>';
+                }
+                echo '</table>';
+        }
+
+        /**
</ins><span class="cx">          * Execute Javascript depending on step.
</span><span class="cx">          *
</span><span class="cx">          * @since unknown
</span><span class="lines">@@ -284,6 +354,7 @@
</span><span class="cx">          * @since unknown
</span><span class="cx">          */
</span><span class="cx">         function step_1() {
</span><ins>+                $this->process_default_headers();
</ins><span class="cx">                 if ( isset($_GET['updated']) && $_GET['updated'] ) { ?>
</span><span class="cx"> <div id="message" class="updated">
</span><span class="cx"> <p><?php printf(__('Header updated. <a href="%s">Visit your site</a> to see how it looks.'), home_url()); ?></p>
</span><span class="lines">@@ -293,6 +364,9 @@
</span><span class="cx"> <div class="wrap">
</span><span class="cx"> <?php screen_icon(); ?>
</span><span class="cx"> <h2><?php _e('Your Header Image'); ?></h2>
</span><ins>+<?php
+if ( get_theme_mod('header_image') || empty($this->default_headers) ) :
+?>
</ins><span class="cx"> <p><?php _e('This is your header image. You can change the text color or upload and crop a new image.'); ?></p>
</span><span class="cx"> <?php
</span><span class="cx">
</span><span class="lines">@@ -310,12 +384,23 @@
</span><span class="cx"> <form method="post" action="<?php echo admin_url('themes.php?page=custom-header&amp;updated=true') ?>">
</span><span class="cx"> <input type="button" class="button" value="<?php esc_attr_e('Hide Text'); ?>" onclick="hide_text()" id="hidetext" />
</span><span class="cx"> <input type="button" class="button" value="<?php esc_attr_e('Select a Text Color'); ?>" id="pickcolor" /><input type="button" class="button" value="<?php esc_attr_e('Use Original Color'); ?>" onclick="colorDefault()" id="defaultcolor" />
</span><del>-<?php wp_nonce_field('custom-header') ?>
</del><ins>+<?php wp_nonce_field('custom-header'); ?>
</ins><span class="cx"> <input type="hidden" name="textcolor" id="textcolor" value="#<?php esc_attr(header_textcolor()) ?>" /><input name="submit" type="submit" class="button" value="<?php esc_attr_e('Save Changes'); ?>" /></form>
</span><span class="cx"> <?php } ?>
</span><span class="cx">
</span><span class="cx"> <div id="colorPickerDiv" style="z-index: 100;background:#eee;border:1px solid #ccc;position:absolute;display:none;"> </div>
</span><span class="cx"> </div>
</span><ins>+<?php
+else:
+        echo '<p>' . __('Choose one of these cool headers, or upload your own image below.') . '</p>';
+        echo '<form method="post" action="' . admin_url('themes.php?page=custom-header&amp;updated=true') . '">';
+        wp_nonce_field('custom-header');
+        $this->show_default_header_selector();
+        echo '<input type="submit" class="button" value="' . esc_attr__('Save Your Choice') . '" />';
+        echo '</form>';
+        echo '</div>';
+endif;
+?>
</ins><span class="cx"> <div class="wrap">
</span><span class="cx"> <h2><?php _e('Upload New Header Image'); ?></h2><p><?php _e('Here you can upload a custom header image to be shown at the top of your blog instead of the default one. On the next screen you will be able to crop the image.'); ?></p>
</span><span class="cx"> <p><?php printf(__('Images of exactly <strong>%1$d x %2$d pixels</strong> will be used as-is.'), HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT); ?></p>
</span></span></pre></div>
<a id="trunkwpcontentthemestwentytenfunctionsphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-content/themes/twentyten/functions.php (13402 => 13403)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-content/themes/twentyten/functions.php        2010-02-25 17:10:00 UTC (rev 13402)
+++ trunk/wp-content/themes/twentyten/functions.php        2010-02-25 19:18:44 UTC (rev 13403)
</span><span class="lines">@@ -9,7 +9,7 @@
</span><span class="cx">         // Your Changeable header business starts here
</span><span class="cx">         // No CSS, just IMG call
</span><span class="cx">         define( 'HEADER_TEXTCOLOR', '');
</span><del>-        define( 'HEADER_IMAGE', '%s/images/header-1.jpg'); // %s is theme dir uri
</del><ins>+        define( 'HEADER_IMAGE', '%s/images/headers/forestfloor.jpg'); // %s is theme dir uri
</ins><span class="cx">         define( 'HEADER_IMAGE_WIDTH', apply_filters( 'twentyten_header_image_width', 940 ) );
</span><span class="cx">         define( 'HEADER_IMAGE_HEIGHT', apply_filters( 'twentyten_header_image_height',        198 ) );
</span><span class="cx">         define( 'NO_HEADER_TEXT', true );
</span><span class="lines">@@ -17,6 +17,15 @@
</span><span class="cx">         add_custom_image_header( '', 'twentyten_admin_header_style' );
</span><span class="cx">         // and thus ends the changeable header business
</span><span class="cx">
</span><ins>+        register_default_headers( array('berries' => array('url' => '%s/images/headers/berries.jpg', 'thumbnail_url' => '%s/images/headers/berries-thumbnail.jpg', 'description' => __('Berries')),
+                                                                        'cherryblossom' => array( 'url' => '%s/images/headers/cherryblossoms.jpg', 'thumbnail_url' => '%s/images/headers/cherryblossoms-thumbnail.jpg', 'description' => __('Cherry Blossoms')),
+                                                                        'concave' => array('url' => '%s/images/headers/concave.jpg', 'thumbnail_url' => '%s/images/headers/concave-thumbnail.jpg', 'description' => __('Concave')),
+                                                                        'fern' => array('url' => '%s/images/headers/fern.jpg', 'thumbnail_url' => '%s/images/headers/fern-thumbnail.jpg', 'description' => __('Fern')),
+                                                                        'forestfloor' => array('url' => '%s/images/headers/forestfloor.jpg', 'thumbnail_url' => '%s/images/headers/forestfloor-thumbnail.jpg', 'description' => __('Forest Floor')),
+                                                                        'inkwell' => array('url' => '%s/images/headers/inkwell.jpg', 'thumbnail_url' => '%s/images/headers/inkwell-thumbnail.jpg', 'description' => __('Ink Well')),
+                                                                        'path' => array('url' => '%s/images/headers/path.jpg', 'thumbnail_url' => '%s/images/headers/path-thumbnail.jpg', 'description' => __('Path')),
+                                                                        'sunset' => array('url' => '%s/images/headers/sunset.jpg', 'thumbnail_url' => '%s/images/headers/sunset-thumbnail.jpg', 'description' => __('Sunset')) ) );
+
</ins><span class="cx">         add_custom_background();
</span><span class="cx">
</span><span class="cx">         // This theme needs post thumbnails
</span></span></pre></div>
<a id="trunkwpincludesthemephp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/theme.php (13402 => 13403)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/theme.php        2010-02-25 17:10:00 UTC (rev 13402)
+++ trunk/wp-includes/theme.php        2010-02-25 19:18:44 UTC (rev 13403)
</span><span class="lines">@@ -1335,6 +1335,19 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><ins>+ * Register a selection of default headers to be displayed by the custom header admin UI.
+ *
+ * @since 3.0.0
+ *
+ * @param array $headers Array of headers keyed by a string id. The ids point to arrays containing 'url', 'thumbnail_url', and 'description' keys.
+ */
+function register_default_headers( $headers ) {
+        global $_wp_default_headers;
+
+        $_wp_default_headers = $headers;
+}
+
+/**
</ins><span class="cx"> * Retrieve background image for custom background.
</span><span class="cx"> *
</span><span class="cx"> * @since 3.0.0
</span></span></pre>
</div>
</div>
</body>
</html>