Ticket #5486: theme-preview.2.diff

File theme-preview.2.diff, 17.6 kB (added by ryan, 6 months ago)

TB fixes

  • wp-includes/theme.php

    old new  
    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

    old new  
    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

    old new  
    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/includes/media.php

    old new  
    194194</style>\n"; 
    195195} 
    196196 
    197 add_action( 'admin_print_scripts', 'media_buttons_head' ); 
     197add_action( 'admin_head-post-new.php', 'media_buttons_head' ); 
     198add_action( 'admin_head-post.php', 'media_buttons_head' ); 
     199add_action( 'admin_head-page-new.php', 'media_buttons_head' ); 
     200add_action( 'admin_head-page.php', 'media_buttons_head' ); 
    198201 
    199202function media_admin_css() { 
    200203        wp_admin_css('css/media'); 
  • wp-admin/js/theme-preview.js

    old new  
     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-includes/js/thickbox/tb-close.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/admin-header.php

    old new  
    4848        do_action('admin_print_scripts-' . $page_hook); 
    4949else if ( isset($plugin_page) ) 
    5050        do_action('admin_print_scripts-' . $plugin_page); 
     51else if ( isset($pagenow) ) 
     52        do_action('admin_print_scripts-' . $pagenow); 
    5153do_action('admin_print_scripts'); 
    5254 
    5355if ( isset($page_hook) ) 
    5456        do_action('admin_head-' . $page_hook); 
    5557else if ( isset($plugin_page) ) 
    5658        do_action('admin_head-' . $plugin_page); 
     59else if ( isset($pagenow) ) 
     60        do_action('admin_head-' . $pagenow); 
    5761do_action('admin_head'); 
    5862?> 
    5963</head> 
  • wp-admin/css/theme-tb.css

    old new  
     1/* ----------------------------------------------------------------------------------------------------------------*/ 
     2/* ---------->>> global settings needed for thickbox <<<-----------------------------------------------------------*/ 
     3/* ----------------------------------------------------------------------------------------------------------------*/ 
     4/* * {padding: 0; margin: 0;} */ 
     5 
     6/* ----------------------------------------------------------------------------------------------------------------*/ 
     7/* ---------->>> thickbox specific link and font settings <<<------------------------------------------------------*/ 
     8/* ----------------------------------------------------------------------------------------------------------------*/ 
     9#TB_window { 
     10        font: 12px Arial, Helvetica, sans-serif; 
     11        color: #333333; 
     12} 
     13 
     14#TB_secondLine { 
     15        font: 10px Arial, Helvetica, sans-serif; 
     16        color:#666666; 
     17} 
     18/* 
     19#TB_window a:link {color: #666666;} 
     20#TB_window a:visited {color: #666666;} 
     21#TB_window a:hover {color: #000;} 
     22#TB_window a:active {color: #666666;} 
     23#TB_window a:focus{color: #666666;} 
     24*/ 
     25/* ----------------------------------------------------------------------------------------------------------------*/ 
     26/* ---------->>> thickbox settings <<<-----------------------------------------------------------------------------*/ 
     27/* ----------------------------------------------------------------------------------------------------------------*/ 
     28#TB_overlay { 
     29        position: fixed; 
     30        z-index:100; 
     31        top: 0px; 
     32        left: 0px; 
     33        background-color:#000; 
     34        filter:alpha(opacity=75); 
     35        -moz-opacity: 0.75; 
     36        opacity: 0.75; 
     37        height:100%; 
     38        width:100%; 
     39} 
     40 
     41* html #TB_overlay { /* ie6 hack */ 
     42     position: absolute; 
     43     height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px'); 
     44} 
     45 
     46#TB_window { 
     47        position: fixed; 
     48        background: #ffffff; 
     49        z-index: 102; 
     50        color:#000000; 
     51        display:none; 
     52        border: 4px solid #525252; 
     53        text-align:left; 
     54        top:50%; 
     55        left:50%; 
     56} 
     57 
     58* html #TB_window { /* ie6 hack */ 
     59position: absolute; 
     60margin-top: expression(0 - parseInt(this.offsetHeight / 2) + (TBWindowMargin = document.documentElement && document.documentElement.scrollTop || document.body.scrollTop) + 'px'); 
     61} 
     62 
     63#TB_window img#TB_Image { 
     64        display:block; 
     65        margin: 15px 0 0 15px; 
     66        border-right: 1px solid #ccc; 
     67        border-bottom: 1px solid #ccc; 
     68        border-top: 1px solid #666; 
     69        border-left: 1px solid #666; 
     70} 
     71 
     72#TB_caption{ 
     73        height:25px; 
     74        padding:7px 30px 10px 25px; 
     75        float:left; 
     76} 
     77 
     78#TB_closeWindow{ 
     79        height:25px; 
     80        padding:11px 25px 10px 0; 
     81        float:right; 
     82} 
     83 
     84#TB_closeAjaxWindow{ 
     85        padding:7px 10px 5px 0; 
     86        margin-bottom:1px; 
     87        text-align:right; 
     88        float:right; 
     89} 
     90 
     91#TB_ajaxWindowTitle{ 
     92        float:left; 
     93        padding:7px 0 5px; 
     94        margin-bottom:1px; 
     95} 
     96 
     97#TB_title{ 
     98        background-color:#e8e8e8; 
     99        height:27px; 
     100} 
     101 
     102#TB_ajaxContent{ 
     103        clear:both; 
     104        padding:2px 15px 15px 15px; 
     105        overflow:auto; 
     106        text-align:left; 
     107        line-height:1.4em; 
     108} 
     109 
     110#TB_ajaxContent.TB_modal{ 
     111        padding:15px; 
     112} 
     113 
     114#TB_ajaxContent p{ 
     115        padding:5px 0px 5px 0px; 
     116} 
     117 
     118#TB_load{ /* WP */ 
     119        background-color: #E8E8E8; 
     120        border: 4px solid #525252; 
     121        position: fixed; 
     122        display:none; 
     123        height:50px; 
     124        width:250px; 
     125        z-index:103; 
     126        top: 50%; 
     127        left: 50%; 
     128        margin: -25px 0 0 -125px; /* -height/2 0 0 -width/2 */ 
     129        padding: 1ex; 
     130} 
     131 
     132* html #TB_load { /* ie6 hack */ 
     133position: absolute; 
     134margin-top: expression(0 - parseInt(this.offsetHeight / 2) + (TBWindowMargin = document.documentElement && document.documentElement.scrollTop || document.body.scrollTop) + 'px'); 
     135} 
     136 
     137#TB_load img { /* WP */ 
     138        position: absolute; 
     139        bottom: 2ex; 
     140        left: 21px; /* (width(TB_load) - width(img))/2 */ 
     141        padding-left: 1ex; 
     142} 
     143 
     144#TB_HideSelect{ 
     145        z-index:99; 
     146        position:fixed; 
     147        top: 0; 
     148        left: 0; 
     149        background-color:#fff; 
     150        border:none; 
     151        filter:alpha(opacity=0); 
     152        -moz-opacity: 0; 
     153        opacity: 0; 
     154        height:100%; 
     155        width:100%; 
     156} 
     157 
     158* html #TB_HideSelect { /* ie6 hack */ 
     159     position: absolute; 
     160     height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px'); 
     161} 
     162 
     163#TB_iframeContent{ 
     164        clear:both; 
     165        border:none; 
     166        margin-bottom:-1px; 
     167        margin-top:1px; 
     168        _margin-bottom:1px; 
     169} 
  • wp-admin/themes.php

    old new  
    11<?php 
    22require_once('admin.php'); 
    33 
     4function switch_themes_css() { 
     5        echo "<style type='text/css' media='all'> 
     6                @import 'css/theme-tb.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