Make WordPress Core

Ticket #5486: theme-preview.diff

File theme-preview.diff, 12.3 KB (added by ryan, 18 years ago)

Rough, TB frame busted

  • wp-includes/theme.php

     
    479479        echo '<link rel="stylesheet" href="' . $stylesheet . '" type="text/css" media="screen" />';
    480480}
    481481
     482function preview_theme() {
     483        if ( ! (isset($_GET['template']) && isset($_GET['preview'])) )
     484                return;
     485
     486        if ( !current_user_can( 'switch_themes' ) )
     487                return;
     488
     489        add_filter('template', create_function('', "return '$_GET[template]';") );
     490
     491        if ( isset($_GET['stylesheet']) )
     492                add_filter('stylesheet', create_function('', "return '$_GET[stylesheet]';") );
     493
     494        ob_start( 'preview_theme_ob_filter' );
     495}
     496add_action('setup_theme', 'preview_theme');
     497
     498function preview_theme_ob_filter( $content ) {
     499        return preg_replace_callback( "|(<a.*?href=([\"']))(.*?)([\"'].*?>)|", 'preview_theme_ob_filter_callback', $content );
     500}
     501
     502function preview_theme_ob_filter_callback( $matches ) {
     503        if (
     504            ( false !== strpos($matches[3], '/wp-admin/') )
     505        ||
     506            ( false !== strpos($matches[3], '://') && 0 !== strpos($matches[3], get_option('home')) )
     507        ||
     508            ( false !== strpos($matches[3], '/feed/') )
     509        ||
     510            ( false !== strpos($matches[3], '/trackback/') )
     511        )
     512                return $matches[1] . "#$matches[2] onclick=$matches[2]return false;" . $matches[4];
     513
     514        $link = add_query_arg( array('preview' => 1, 'template' => $_GET['template'], 'stylesheet' => @$_GET['stylesheet'] ), $matches[3] );
     515        if ( 0 === strpos($link, 'preview=1') )
     516                $link = "?$link";
     517        return $matches[1] . attribute_escape( $link ) . $matches[4];
     518}
     519
    482520function switch_theme($template, $stylesheet) {
    483521        update_option('template', $template);
    484522        update_option('stylesheet', $stylesheet);
  • wp-settings.php

     
    425425 */
    426426$wp           =& new WP();
    427427
     428$wp->init();  // Sets up current user.
    428429
    429 /**
    430  * Web Path to the current active template directory
    431  * @since 1.5
    432  */
    433 define('TEMPLATEPATH', get_template_directory());
    434 
    435 /**
    436  * Web Path to the current active template stylesheet directory
    437  * @since 2.1
    438  */
    439 define('STYLESHEETPATH', get_stylesheet_directory());
    440 
    441430// Load the default text localization domain.
    442431load_default_textdomain();
    443432
     
    460449 */
    461450$wp_locale =& new WP_Locale();
    462451
     452do_action('setup_theme');
     453
     454/**
     455 * Web Path to the current active template directory
     456 * @since 1.5
     457 */
     458define('TEMPLATEPATH', get_template_directory());
     459
     460/**
     461 * Web Path to the current active template stylesheet directory
     462 * @since 2.1
     463 */
     464define('STYLESHEETPATH', get_stylesheet_directory());
     465
    463466// Load functions for active theme.
    464467if ( TEMPLATEPATH !== STYLESHEETPATH && file_exists(STYLESHEETPATH . '/functions.php') )
    465468        include(STYLESHEETPATH . '/functions.php');
     
    478481}
    479482register_shutdown_function('shutdown_action_hook');
    480483
    481 $wp->init();  // Sets up current user.
    482 
    483484// Everything is loaded and initialized.
    484485do_action('init');
    485486
  • wp-admin/wp-admin.css

     
    5252        margin: 10px 20px 10px 20px;
    5353}
    5454
    55 .available-theme {
    56         width: 30%;
    57         margin: 0 1em;
    58         float: left;
    59         text-align: center;
    60         height: 28em;
    61         overflow: hidden;
     55table#availablethemes {
     56        border-spacing: 0px;
     57        border: none;
     58        border-top: 1px solid #ccc;
     59        border-bottom: 1px solid #ccc;
     60        margin: 10px auto;
    6261}
     62td.available-theme {
     63        vertical-align: top;
     64        width: 240px;
     65        margin: 0;
     66        padding: 20px;
     67        text-align: left;
     68}
     69table#availablethemes td {
     70        border: 1px solid #eee;
     71        border-top: none;
     72}
     73table#availablethemes td.top {
     74        border-top: none;
     75}
     76table#availablethemes td.right {
     77        border-right: none;
     78        border-left: none;
     79}
     80table#availablethemes td.bottom {
     81        border-bottom: none;
     82}
     83table#availablethemes td.left {
     84        border-right: none;
     85        border-left: none;
     86}
    6387
    6488.available-theme a.screenshot {
    65         width: 250px;
    66         height: 200px;
     89        width: 240px;
     90        height: 180px;
    6791        display: block;
    68         margin: auto;
     92        border: 1px solid #efefef;
    6993        margin-bottom: 10px;
    7094        overflow: hidden;
    71         border-width: 1px;
    72         border-style: solid;
    7395}
    74 
    7596.available-theme img {
    76         width: 100%;
     97        width: 240px;
    7798}
     99.available-theme h3 {
     100        margin: 15px 0 5px;
     101}
    78102
     103#current-theme {
     104        margin-top: 1em;
     105}
     106
     107#current-theme a {
     108        border-bottom: none;
     109}
     110
     111#current-theme h3 {
     112        font-size: 17px;
     113        font-weight: normal;
     114        margin: 0;
     115}
     116
     117#current-theme .description {
     118        margin-top: 5px;
     119}
     120
     121#current-theme img {
     122        float: left;
     123        border: 1px solid #666;
     124        margin-right: 1em;
     125        margin-bottom: 1.5em;
     126        width: 150px;
     127}
     128
    79129.checkbox {
    80130        border: none;
    81131        margin: 0;
     
    249299        border-collapse: separate;
    250300}
    251301
    252 #currenttheme img {
    253         float: left;
    254         margin-right: 1em;
    255         margin-bottom: 1.5em;
    256         width: 300px;
    257         border-width: 1px;
    258         border-style: solid;
    259 }
    260 
    261302#quicktags {
    262303        padding: 0;
    263304        border: 0 none;
  • wp-admin/js/theme-preview.js

     
     1jQuery(function($) {
     2        if ( 'undefined' == typeof $.fn.pngFix )
     3                $.fn.pngFix = function() { return this; }
     4
     5        var thickDims = function() {
     6                var width = $(window).width();
     7                var height = $(window).height();
     8
     9                var tbWindow = $('#TB_window');
     10                if ( tbWindow.size() ) {
     11                        tbWindow.width( width - 100 ).height( height - 60 );
     12                        tb_position( width - 70, height - 60 );
     13                        $('#TB_iframeContent').height( height - 88 );
     14                }
     15
     16                return $('a.thickbox').each( function() {
     17                        var href = $(this).parents('.available-theme').find('.previewlink').attr('href');
     18                        if ( !href )
     19                                return;
     20                        href = href.replace(/&width=[0-9]+/g, '');
     21                        href = href.replace(/&height=[0-9]+/g, '');
     22                        $(this).attr( 'href', href + '&width=' + ( width - 100 ) + '&height=' + ( height - 100 ) );
     23                } );
     24        }
     25
     26        thickDims()
     27        .click( function() {
     28                var alink = $(this).parents('.available-theme').find('.activatelink');
     29                var url = alink.attr('href');
     30                var text = alink.html();
     31
     32                var img = $('<img id="TB-close-png" src="/wp-admin/images/close-button.png" alt="close" title="close" />')
     33                        .wrap('<a href="#" id="TB-close-link" style="float: left; border-bottom: none;" onclick="tb_remove(); return false;"></a>')
     34                        .css( { width: 28, height: 28 } )
     35                        .parent().pngFix();
     36
     37                $('#TB_ajaxWindowTitle')
     38                        .before(img)
     39                        .append('&nbsp;<a href="' + url + '" target="_top" style="position: absolute; right: 1ex; font-weight: bold;">' + text + ' &raquo;</a>');
     40
     41                $('#TB_iframeContent').width('100%');
     42                return false;
     43        } );
     44
     45        $(window).resize( function() { thickDims() } );
     46});
  • wp-admin/themes.php

    Cannot display: file marked as a binary type.
    svn:mime-type = application/octet-stream
    
    Property changes on: wp-admin/images/close-button.png
    ___________________________________________________________________
    Name: svn:mime-type
       + application/octet-stream
    
     
    11<?php
    22require_once('admin.php');
    33
     4function switch_themes_css() {
     5        echo "<style type='text/css' media='all'>
     6                @import '../wp-includes/js/jquery/thickbox.css?1';
     7                #TB_closeWindow, #TB_closeAjaxWindow { display: none; }
     8                </style>\n";
     9}
     10
    411if ( isset($_GET['action']) ) {
    512        check_admin_referer('switch-theme_' . $_GET['template']);
    613
     
    1320
    1421$title = __('Manage Themes');
    1522$parent_file = 'themes.php';
     23
     24wp_enqueue_script( 'theme-preview', '/wp-admin/js/theme-preview.js', array( 'thickbox', 'dimensions' ), 5 );
     25
     26add_action( 'admin_head', 'switch_themes_css' );
     27
    1628require_once('admin-header.php');
    1729?>
    1830
     
    2941
    3042<div class="wrap">
    3143<h2><?php _e('Current Theme'); ?></h2>
    32 <div id="currenttheme">
     44<div id="current-theme">
    3345<?php if ( $ct->screenshot ) : ?>
    3446<img src="<?php echo get_option('siteurl') . '/' . $ct->stylesheet_dir . '/' . $ct->screenshot; ?>" alt="<?php _e('Current theme preview'); ?>" />
    3547<?php endif; ?>
    3648<h3><?php printf(_c('%1$s %2$s by %3$s|1: theme title, 2: theme version, 3: theme author'), $ct->title, $ct->version, $ct->author) ; ?></h3>
    37 <p><?php echo $ct->description; ?></p>
     49<p class="description"><?php echo $ct->description; ?></p>
    3850<?php if ($ct->parent_theme) { ?>
    3951        <p><?php printf(__('The template files are located in <code>%2$s</code>.  The stylesheet files are located in <code>%3$s</code>.  <strong>%4$s</strong> uses templates from <strong>%5$s</strong>.  Changes made to the templates will affect both themes.'), $ct->title, $ct->template_dir, $ct->stylesheet_dir, $ct->title, $ct->parent_theme); ?></p>
    4052<?php } else { ?>
     
    4759
    4860<h2><?php _e('Available Themes'); ?></h2>
    4961<?php if ( 1 < count($themes) ) { ?>
    50 
     62<table id="availablethemes" cellspacing="0" cellpadding="0">
    5163<?php
    5264$style = '';
    5365
    5466$theme_names = array_keys($themes);
    5567natcasesort($theme_names);
    5668
    57 foreach ($theme_names as $theme_name) {
    58         if ( $theme_name == $ct->name )
    59                 continue;
     69$rows = ceil(count($theme_names) / 3);
     70for ( $row = 1; $row <= $rows; $row++ )
     71        for ( $col = 1; $col <= 3; $col++ )
     72                $table[$row][$col] = array_shift($theme_names);
     73
     74foreach ( $table as $row => $cols ) {
     75?>
     76<tr>
     77<?php
     78foreach ( $cols as $col => $theme_name ) {
     79        $class = array('available-theme');
     80        if ( $row == 1 ) $class[] = 'top';
     81        if ( $col == 1 ) $class[] = 'left';
     82        if ( $row == $rows ) $class[] = 'bottom';
     83        if ( $col == 3 ) $class[] = 'right';
     84?>
     85        <td class="<?php echo join(' ', $class); ?>">
     86<?php if ( !empty($theme_name) ) :
    6087        $template = $themes[$theme_name]['Template'];
    6188        $stylesheet = $themes[$theme_name]['Stylesheet'];
    6289        $title = $themes[$theme_name]['Title'];
     
    6592        $author = $themes[$theme_name]['Author'];
    6693        $screenshot = $themes[$theme_name]['Screenshot'];
    6794        $stylesheet_dir = $themes[$theme_name]['Stylesheet Dir'];
     95        $preview_link = clean_url( get_option('home') . '/');
     96        $preview_link = add_query_arg( array('preview' => 1, 'template' => $template, 'stylesheet' => $stylesheet, 'TB_iframe' => 'true', 'width' => 600, 'height' => 400 ), $preview_link );
     97        $preview_text = attribute_escape( sprintf( __('Preview of "%s"'), $title ) );
    6898        $tags = $themes[$theme_name]['Tags'];
     99        $thickbox_class = 'thickbox';
    69100        $activate_link = wp_nonce_url("themes.php?action=activate&amp;template=".urlencode($template)."&amp;stylesheet=".urlencode($stylesheet), 'switch-theme_' . $template);
     101        $activate_text = attribute_escape( sprintf( __('Activate "%s"'), $title ) );
    70102?>
    71 <div class="available-theme">
    72 <h3><a href="<?php echo $activate_link; ?>"><?php echo $title; ?></a></h3>
    73 
    74 <a href="<?php echo $activate_link; ?>" class="screenshot">
     103                <a href="<?php echo $activate_link; ?>" class="<?php echo $thickbox_class; ?> screenshot">
    75104<?php if ( $screenshot ) : ?>
    76 <img src="<?php echo get_option('siteurl') . '/' . $stylesheet_dir . '/' . $screenshot; ?>" alt="" />
     105                        <img src="<?php echo ( $tpage == 'stage' ) ? $screenshot : get_option('siteurl') . '/' . $stylesheet_dir . '/' . $screenshot; ?>" alt="" />
    77106<?php endif; ?>
    78 </a>
    79 
    80 <p><?php echo $description; ?></p>
     107                </a>
     108                <h3><a class="<?php echo $thickbox_class; ?>" href="<?php echo $activate_link; ?>"><?php echo $title; ?></a></h3>
     109                <p><?php echo $description; ?></p>
    81110<?php if ( $tags ) : ?>
    82 <p><?php _e('Tags:'); ?> <?php echo join(', ', $tags); ?></p>
     111                <p><?php _e('Tags:'); ?> <?php echo join(', ', $tags); ?></p>
     112                <noscript><p class="themeactions"><a href="<?php echo $preview_link; ?>" title="<?php echo $preview_text; ?>"><?php _e('Preview'); ?></a> <a href="<?php echo $activate_link; ?>" title="<?php echo $activate_text; ?>"><?php _e('Activate'); ?></a></p></noscript>
    83113<?php endif; ?>
    84 </div>
    85 <?php } // end foreach theme_names ?>
    86 
     114                <div style="display:none;"><a class="previewlink" href="<?php echo $preview_link; ?>"><?php echo $preview_text; ?></a> <a class="activatelink" href="<?php echo $activate_link; ?>"><?php echo $activate_text; ?></a></div>
     115<?php endif; // end if not empty theme_name ?>
     116        </td>
     117<?php } // end foreach $cols ?>
     118</tr>
     119<?php } // end foreach $table ?>
     120</table>
    87121<?php } ?>
    88122
    89123<?php