Ticket #5486: theme-preview.diff
| File theme-preview.diff, 12.3 KB (added by , 18 years ago) |
|---|
-
wp-includes/theme.php
479 479 echo '<link rel="stylesheet" href="' . $stylesheet . '" type="text/css" media="screen" />'; 480 480 } 481 481 482 function 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 } 496 add_action('setup_theme', 'preview_theme'); 497 498 function preview_theme_ob_filter( $content ) { 499 return preg_replace_callback( "|(<a.*?href=([\"']))(.*?)([\"'].*?>)|", 'preview_theme_ob_filter_callback', $content ); 500 } 501 502 function 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 482 520 function switch_theme($template, $stylesheet) { 483 521 update_option('template', $template); 484 522 update_option('stylesheet', $stylesheet); -
wp-settings.php
425 425 */ 426 426 $wp =& new WP(); 427 427 428 $wp->init(); // Sets up current user. 428 429 429 /**430 * Web Path to the current active template directory431 * @since 1.5432 */433 define('TEMPLATEPATH', get_template_directory());434 435 /**436 * Web Path to the current active template stylesheet directory437 * @since 2.1438 */439 define('STYLESHEETPATH', get_stylesheet_directory());440 441 430 // Load the default text localization domain. 442 431 load_default_textdomain(); 443 432 … … 460 449 */ 461 450 $wp_locale =& new WP_Locale(); 462 451 452 do_action('setup_theme'); 453 454 /** 455 * Web Path to the current active template directory 456 * @since 1.5 457 */ 458 define('TEMPLATEPATH', get_template_directory()); 459 460 /** 461 * Web Path to the current active template stylesheet directory 462 * @since 2.1 463 */ 464 define('STYLESHEETPATH', get_stylesheet_directory()); 465 463 466 // Load functions for active theme. 464 467 if ( TEMPLATEPATH !== STYLESHEETPATH && file_exists(STYLESHEETPATH . '/functions.php') ) 465 468 include(STYLESHEETPATH . '/functions.php'); … … 478 481 } 479 482 register_shutdown_function('shutdown_action_hook'); 480 483 481 $wp->init(); // Sets up current user.482 483 484 // Everything is loaded and initialized. 484 485 do_action('init'); 485 486 -
wp-admin/wp-admin.css
52 52 margin: 10px 20px 10px 20px; 53 53 } 54 54 55 .available-theme { 56 width: 30%; 57 margin: 0 1em; 58 float: left; 59 text-align: center; 60 height: 28em; 61 overflow: hidden; 55 table#availablethemes { 56 border-spacing: 0px; 57 border: none; 58 border-top: 1px solid #ccc; 59 border-bottom: 1px solid #ccc; 60 margin: 10px auto; 62 61 } 62 td.available-theme { 63 vertical-align: top; 64 width: 240px; 65 margin: 0; 66 padding: 20px; 67 text-align: left; 68 } 69 table#availablethemes td { 70 border: 1px solid #eee; 71 border-top: none; 72 } 73 table#availablethemes td.top { 74 border-top: none; 75 } 76 table#availablethemes td.right { 77 border-right: none; 78 border-left: none; 79 } 80 table#availablethemes td.bottom { 81 border-bottom: none; 82 } 83 table#availablethemes td.left { 84 border-right: none; 85 border-left: none; 86 } 63 87 64 88 .available-theme a.screenshot { 65 width: 2 50px;66 height: 200px;89 width: 240px; 90 height: 180px; 67 91 display: block; 68 margin: auto;92 border: 1px solid #efefef; 69 93 margin-bottom: 10px; 70 94 overflow: hidden; 71 border-width: 1px;72 border-style: solid;73 95 } 74 75 96 .available-theme img { 76 width: 100%;97 width: 240px; 77 98 } 99 .available-theme h3 { 100 margin: 15px 0 5px; 101 } 78 102 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 79 129 .checkbox { 80 130 border: none; 81 131 margin: 0; … … 249 299 border-collapse: separate; 250 300 } 251 301 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 261 302 #quicktags { 262 303 padding: 0; 263 304 border: 0 none; -
wp-admin/js/theme-preview.js
1 jQuery(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(' <a href="' + url + '" target="_top" style="position: absolute; right: 1ex; font-weight: bold;">' + text + ' »</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
1 1 <?php 2 2 require_once('admin.php'); 3 3 4 function 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 4 11 if ( isset($_GET['action']) ) { 5 12 check_admin_referer('switch-theme_' . $_GET['template']); 6 13 … … 13 20 14 21 $title = __('Manage Themes'); 15 22 $parent_file = 'themes.php'; 23 24 wp_enqueue_script( 'theme-preview', '/wp-admin/js/theme-preview.js', array( 'thickbox', 'dimensions' ), 5 ); 25 26 add_action( 'admin_head', 'switch_themes_css' ); 27 16 28 require_once('admin-header.php'); 17 29 ?> 18 30 … … 29 41 30 42 <div class="wrap"> 31 43 <h2><?php _e('Current Theme'); ?></h2> 32 <div id="current theme">44 <div id="current-theme"> 33 45 <?php if ( $ct->screenshot ) : ?> 34 46 <img src="<?php echo get_option('siteurl') . '/' . $ct->stylesheet_dir . '/' . $ct->screenshot; ?>" alt="<?php _e('Current theme preview'); ?>" /> 35 47 <?php endif; ?> 36 48 <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> 38 50 <?php if ($ct->parent_theme) { ?> 39 51 <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> 40 52 <?php } else { ?> … … 47 59 48 60 <h2><?php _e('Available Themes'); ?></h2> 49 61 <?php if ( 1 < count($themes) ) { ?> 50 62 <table id="availablethemes" cellspacing="0" cellpadding="0"> 51 63 <?php 52 64 $style = ''; 53 65 54 66 $theme_names = array_keys($themes); 55 67 natcasesort($theme_names); 56 68 57 foreach ($theme_names as $theme_name) { 58 if ( $theme_name == $ct->name ) 59 continue; 69 $rows = ceil(count($theme_names) / 3); 70 for ( $row = 1; $row <= $rows; $row++ ) 71 for ( $col = 1; $col <= 3; $col++ ) 72 $table[$row][$col] = array_shift($theme_names); 73 74 foreach ( $table as $row => $cols ) { 75 ?> 76 <tr> 77 <?php 78 foreach ( $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) ) : 60 87 $template = $themes[$theme_name]['Template']; 61 88 $stylesheet = $themes[$theme_name]['Stylesheet']; 62 89 $title = $themes[$theme_name]['Title']; … … 65 92 $author = $themes[$theme_name]['Author']; 66 93 $screenshot = $themes[$theme_name]['Screenshot']; 67 94 $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 ) ); 68 98 $tags = $themes[$theme_name]['Tags']; 99 $thickbox_class = 'thickbox'; 69 100 $activate_link = wp_nonce_url("themes.php?action=activate&template=".urlencode($template)."&stylesheet=".urlencode($stylesheet), 'switch-theme_' . $template); 101 $activate_text = attribute_escape( sprintf( __('Activate "%s"'), $title ) ); 70 102 ?> 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"> 75 104 <?php if ( $screenshot ) : ?> 76 <img src="<?php echoget_option('siteurl') . '/' . $stylesheet_dir . '/' . $screenshot; ?>" alt="" />105 <img src="<?php echo ( $tpage == 'stage' ) ? $screenshot : get_option('siteurl') . '/' . $stylesheet_dir . '/' . $screenshot; ?>" alt="" /> 77 106 <?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> 81 110 <?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> 83 113 <?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> 87 121 <?php } ?> 88 122 89 123 <?php