Ticket #5486: theme-preview.2.diff
File theme-preview.2.diff, 17.6 KB (added by , 16 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/includes/media.php
194 194 </style>\n"; 195 195 } 196 196 197 add_action( 'admin_print_scripts', 'media_buttons_head' ); 197 add_action( 'admin_head-post-new.php', 'media_buttons_head' ); 198 add_action( 'admin_head-post.php', 'media_buttons_head' ); 199 add_action( 'admin_head-page-new.php', 'media_buttons_head' ); 200 add_action( 'admin_head-page.php', 'media_buttons_head' ); 198 201 199 202 function media_admin_css() { 200 203 wp_admin_css('css/media'); -
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-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(' <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/admin-header.php
48 48 do_action('admin_print_scripts-' . $page_hook); 49 49 else if ( isset($plugin_page) ) 50 50 do_action('admin_print_scripts-' . $plugin_page); 51 else if ( isset($pagenow) ) 52 do_action('admin_print_scripts-' . $pagenow); 51 53 do_action('admin_print_scripts'); 52 54 53 55 if ( isset($page_hook) ) 54 56 do_action('admin_head-' . $page_hook); 55 57 else if ( isset($plugin_page) ) 56 58 do_action('admin_head-' . $plugin_page); 59 else if ( isset($pagenow) ) 60 do_action('admin_head-' . $pagenow); 57 61 do_action('admin_head'); 58 62 ?> 59 63 </head> -
wp-admin/css/theme-tb.css
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 */ 59 position: absolute; 60 margin-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 */ 133 position: absolute; 134 margin-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
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 'css/theme-tb.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