X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/177fd6fefd2e3d5a0ea6591c71d660cabdb3c1a4..refs/tags/wordpress-2.6.2:/wp-includes/theme.php diff --git a/wp-includes/theme.php b/wp-includes/theme.php index 984b4ee2..2ed73358 100644 --- a/wp-includes/theme.php +++ b/wp-includes/theme.php @@ -128,8 +128,8 @@ function get_themes() { $themes = array(); $wp_broken_themes = array(); $theme_loc = $theme_root = get_theme_root(); - if ( '/' != ABSPATH ) // don't want to replace all forward slashes, see Trac #4541 - $theme_loc = str_replace(ABSPATH, '', $theme_root); + if ( '/' != WP_CONTENT_DIR ) // don't want to replace all forward slashes, see Trac #4541 + $theme_loc = str_replace(WP_CONTENT_DIR, '', $theme_root); // Files in wp-content/themes directory and one subdir down $themes_dir = @ opendir($theme_root); @@ -333,11 +333,11 @@ function get_current_theme() { } function get_theme_root() { - return apply_filters('theme_root', ABSPATH . "wp-content/themes"); + return apply_filters('theme_root', WP_CONTENT_DIR . "/themes"); } function get_theme_root_uri() { - return apply_filters('theme_root_uri', get_option('siteurl') . "/wp-content/themes", get_option('siteurl')); + return apply_filters('theme_root_uri', content_url('themes'), get_option('siteurl')); } function get_query_template($type) { @@ -419,7 +419,7 @@ function get_page_template() { if ( 'default' == $template ) $template = ''; - if ( !empty($template) && file_exists(TEMPLATEPATH . "/$template") ) + if ( !empty($template) && !validate_file($template) && file_exists(TEMPLATEPATH . "/$template") ) $template = TEMPLATEPATH . "/$template"; elseif ( file_exists(TEMPLATEPATH . "/page.php") ) $template = TEMPLATEPATH . "/page.php"; @@ -479,6 +479,53 @@ function locale_stylesheet() { echo ''; } +function preview_theme() { + if ( ! (isset($_GET['template']) && isset($_GET['preview'])) ) + return; + + if ( !current_user_can( 'switch_themes' ) ) + return; + + $_GET[template] = preg_replace('|[^a-z0-9_.-]|i', '', $_GET[template]); + + if ( validate_file($_GET[template]) ) + return; + + add_filter('template', create_function('', "return '$_GET[template]';") ); + + if ( isset($_GET['stylesheet']) ) { + $_GET[stylesheet] = preg_replace('|[^a-z0-9_.-]|i', '', $_GET[stylesheet]); + if ( validate_file($_GET[stylesheet]) ) + return; + add_filter('stylesheet', create_function('', "return '$_GET[stylesheet]';") ); + } + + ob_start( 'preview_theme_ob_filter' ); +} +add_action('setup_theme', 'preview_theme'); + +function preview_theme_ob_filter( $content ) { + return preg_replace_callback( "|()|", 'preview_theme_ob_filter_callback', $content ); +} + +function preview_theme_ob_filter_callback( $matches ) { + if ( + ( false !== strpos($matches[3], '/wp-admin/') ) + || + ( false !== strpos($matches[3], '://') && 0 !== strpos($matches[3], get_option('home')) ) + || + ( false !== strpos($matches[3], '/feed/') ) + || + ( false !== strpos($matches[3], '/trackback/') ) + ) + return $matches[1] . "#$matches[2] onclick=$matches[2]return false;" . $matches[4]; + + $link = add_query_arg( array('preview' => 1, 'template' => $_GET['template'], 'stylesheet' => @$_GET['stylesheet'] ), $matches[3] ); + if ( 0 === strpos($link, 'preview=1') ) + $link = "?$link"; + return $matches[1] . attribute_escape( $link ) . $matches[4]; +} + function switch_theme($template, $stylesheet) { update_option('template', $template); update_option('stylesheet', $stylesheet);