Fix preview for theme installer. see #8652

git-svn-id: http://svn.automattic.com/wordpress/trunk@10590 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2009-02-18 21:55:00 +00:00
parent 062c0c6ac0
commit c6ecb155d6
6 changed files with 28 additions and 23 deletions

View File

@ -6,6 +6,13 @@
* @subpackage Administration
*/
$themes_allowedtags = array('a' => array('href' => array(), 'title' => array(), 'target' => array()),
'abbr' => array('title' => array()), 'acronym' => array('title' => array()),
'code' => array(), 'pre' => array(), 'em' => array(), 'strong' => array(),
'div' => array(), 'p' => array(), 'ul' => array(), 'ol' => array(), 'li' => array(),
'h1' => array(), 'h2' => array(), 'h3' => array(), 'h4' => array(), 'h5' => array(), 'h6' => array(),
'img' => array('src' => array(), 'class' => array(), 'alt' => array()));
/**
* Retrieve theme installer pages from WordPress Themes API.
*
@ -257,6 +264,8 @@ function install_themes_upload() {
* @param int $totalpages Number of pages.
*/
function display_themes($themes, $page = 1, $totalpages = 1) {
global $themes_allowedtags;
$type = isset($_REQUEST['type']) ? stripslashes( $_REQUEST['type'] ) : '';
$term = isset($_REQUEST['s']) ? stripslashes( $_REQUEST['s'] ) : '';
@ -298,26 +307,26 @@ function display_themes($themes, $page = 1, $totalpages = 1) {
$name = wp_kses($theme->name, $themes_allowedtags);
$desc = wp_kses($theme->description, $themes_allowedtags);
if ( strlen($desc) > 30 )
$desc = substr($desc, 0, 30) . '<span class="dots">...</span><span>' . substr($desc, 30) . '</span>';
//if ( strlen($desc) > 30 )
// $desc = substr($desc, 0, 30) . '<span class="dots">...</span><span>' . substr($desc, 30) . '</span>';
$preview_link = $theme->preview_url . '?TB_iframe=true&amp;width=600&amp;height=400';
$action_links = array();
$action_links[] = '<a href="' . admin_url('theme-install.php?tab=theme-information&amp;theme=' . $theme->slug .
'&amp;TB_iframe=true&amp;width=600&amp;height=800') . '" class="thickbox onclick" title="' .
attribute_escape($name) . '">' . __('Install') . '</a>';
$action_links[] = '<a href="' . $theme->preview_url . '&TB_iframe" class="thickbox onclick" title="' .
attribute_escape( sprintf(__('Preview %s'), $name) ) . '">' . __('Preview') . '</a>';
'&amp;TB_iframe=true&amp;width=600&amp;height=800') . '" class="button thickbox onclick">' . __('Install') . '</a>';
$action_links[] = '<a href="' . $preview_link . '" class="button thickbox onclick previewlink">' . __('Preview') . '</a>';
$action_links = apply_filters('theme_install_action_links', $action_links, $theme);
$actions = implode ( ' | ', $action_links );
$actions = implode ( ' ', $action_links );
echo "
<div class='theme-item'>
<h3>{$theme->name}</h3>
<img src='{$theme->screenshot_url}' width='150' /><br />
<div class='theme-item available-theme'>
<a class='thickbox screenshot' href='$preview_link'>
<img src='{$theme->screenshot_url}' width='150' />
</a>
<h3>{$name}</h3>
<span class='action-links'>$actions</span>
<div class='theme-item-info'>
{$desc}
<br class='line' />
<span class='action-links'>$actions</span>
</div>
</div>";
/*
@ -357,19 +366,13 @@ add_action('install_themes_pre_theme-information', 'install_theme_information');
*/
function install_theme_information() {
//TODO: This function needs a LOT of UI work :)
global $tab;
global $tab, $themes_allowedtags;;
$api = themes_api('theme_information', array('slug' => stripslashes( $_REQUEST['theme'] ) ));
if ( is_wp_error($api) )
wp_die($api);
$themes_allowedtags = array('a' => array('href' => array(), 'title' => array(), 'target' => array()),
'abbr' => array('title' => array()), 'acronym' => array('title' => array()),
'code' => array(), 'pre' => array(), 'em' => array(), 'strong' => array(),
'div' => array(), 'p' => array(), 'ul' => array(), 'ol' => array(), 'li' => array(),
'h1' => array(), 'h2' => array(), 'h3' => array(), 'h4' => array(), 'h5' => array(), 'h6' => array(),
'img' => array('src' => array(), 'class' => array(), 'alt' => array()));
//Sanitize HTML
foreach ( (array)$api->sections as $section_name => $content )
$api->sections[$section_name] = wp_kses($content, $themes_allowedtags);

View File

@ -14,7 +14,7 @@ jQuery(document).ready(function($) {
};
return $('a.thickbox').each( function() {
var href = $(this).parents('.available-theme').find('.previewlink').attr('href');
var href = $(this).attr('href');
if ( ! href ) return;
href = href.replace(/&width=[0-9]+/g, '');
href = href.replace(/&height=[0-9]+/g, '');
@ -26,6 +26,7 @@ jQuery(document).ready(function($) {
.click( function() {
var alink = $(this).parents('.available-theme').find('.activatelink'), url = alink.attr('href'), text = alink.html();
if ( null == text ) text = '';
$('#TB_title').css({'background-color':'#222','color':'#cfcfcf'});
$('#TB_closeAjaxWindow').css({'float':'left'});
$('#TB_ajaxWindowTitle').css({'float':'right'})

View File

@ -1 +1 @@
var thickDims;jQuery(document).ready(function(a){thickDims=function(){var d=a("#TB_window"),c=a(window).height(),b=a(window).width();if(d.size()){d.width(b-90).height(c-60);a("#TB_iframeContent").width(b-90).height(c-90);d.css({"margin-left":"-"+parseInt(((b-90)/2),10)+"px"});if(typeof document.body.style.maxWidth!="undefined"){d.css({top:"30px","margin-top":"0"})}}return a("a.thickbox").each(function(){var e=a(this).parents(".available-theme").find(".previewlink").attr("href");if(!e){return}e=e.replace(/&width=[0-9]+/g,"");e=e.replace(/&height=[0-9]+/g,"");a(this).attr("href",e+"&width="+(b-110)+"&height="+(c-100))})};thickDims().click(function(){var c=a(this).parents(".available-theme").find(".activatelink"),b=c.attr("href"),d=c.html();a("#TB_title").css({"background-color":"#222",color:"#cfcfcf"});a("#TB_closeAjaxWindow").css({"float":"left"});a("#TB_ajaxWindowTitle").css({"float":"right"}).append('&nbsp;<a href="'+b+'" target="_top" class="tb-theme-preview-link">'+d+"</a>");a("#TB_iframeContent").width("100%");return false});a(window).resize(function(){thickDims()})});function tb_position(){thickDims()};
var thickDims;jQuery(document).ready(function(a){thickDims=function(){var d=a("#TB_window"),c=a(window).height(),b=a(window).width();if(d.size()){d.width(b-90).height(c-60);a("#TB_iframeContent").width(b-90).height(c-90);d.css({"margin-left":"-"+parseInt(((b-90)/2),10)+"px"});if(typeof document.body.style.maxWidth!="undefined"){d.css({top:"30px","margin-top":"0"})}}return a("a.thickbox").each(function(){var e=a(this).attr("href");if(!e){return}e=e.replace(/&width=[0-9]+/g,"");e=e.replace(/&height=[0-9]+/g,"");a(this).attr("href",e+"&width="+(b-110)+"&height="+(c-100))})};thickDims().click(function(){var c=a(this).parents(".available-theme").find(".activatelink"),b=c.attr("href"),d=c.html();if(null==d){d=""}a("#TB_title").css({"background-color":"#222",color:"#cfcfcf"});a("#TB_closeAjaxWindow").css({"float":"left"});a("#TB_ajaxWindowTitle").css({"float":"right"}).append('&nbsp;<a href="'+b+'" target="_top" class="tb-theme-preview-link">'+d+"</a>");a("#TB_iframeContent").width("100%");return false});a(window).resize(function(){thickDims()})});function tb_position(){thickDims()};

View File

@ -22,6 +22,7 @@ wp_enqueue_style( 'theme-install' );
wp_enqueue_script( 'theme-install' );
add_thickbox();
wp_enqueue_script( 'theme-preview' );
//These are the tabs which are shown on the page,
$tabs = array();

View File

@ -178,7 +178,7 @@ foreach ( $cols as $col => $theme_name ) {
$activate_link = wp_nonce_url("themes.php?action=activate&amp;template=".urlencode($template)."&amp;stylesheet=".urlencode($stylesheet), 'switch-theme_' . $template);
$activate_text = attribute_escape( sprintf( __('Activate "%s"'), $title ) );
?>
<a href="<?php echo $activate_link; ?>" class="<?php echo $thickbox_class; ?> screenshot">
<a href="<?php echo $preview_link; ?>" class="<?php echo $thickbox_class; ?> screenshot">
<?php if ( $screenshot ) : ?>
<img src="<?php echo WP_CONTENT_URL . $stylesheet_dir . '/' . $screenshot; ?>" alt="" />
<?php endif; ?>

View File

@ -341,7 +341,7 @@ function wp_default_scripts( &$scripts ) {
'l10n_print_after' => 'try{convertEntities(wpGearsL10n);}catch(e){};'
));
$scripts->add( 'theme-preview', "/wp-admin/js/theme-preview$suffix.js", array( 'thickbox', 'jquery' ), '20090114' );
$scripts->add( 'theme-preview', "/wp-admin/js/theme-preview$suffix.js", array( 'thickbox', 'jquery' ), '20090218' );
$scripts->add_data( 'theme-preview', 'group', 1 );
$scripts->add( 'inline-edit-post', "/wp-admin/js/inline-edit-post$suffix.js", array( 'jquery-form', 'suggest' ), '20090125' );