Show template files in subdirs. Props DD32. fixes #4131

git-svn-id: http://svn.automattic.com/wordpress/trunk@10835 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2009-03-25 16:51:08 +00:00
parent 61ff5addca
commit a3d28151b2
3 changed files with 44 additions and 7 deletions

View File

@ -139,7 +139,7 @@ function get_page_templates() {
$name = $name[1];
if ( !empty( $name ) ) {
$page_templates[trim( $name )] = basename( $template );
$page_templates[trim( $name )] = theme_basename( $template );
}
}
}

View File

@ -151,7 +151,7 @@ if ($allowed_files) :
<?php
$template_mapping = array();
$template_dir = $themes[$theme]['Template Dir'];
foreach($themes[$theme]['Template Files'] as $template_file) {
foreach ( $themes[$theme]['Template Files'] as $template_file ) {
$description = trim( get_file_description($template_file) );
$template_show = basename($template_file);
$filedesc = ( $description != $template_file ) ? "$description <span class='nonessential'>($template_show)</span>" : "$description";
@ -177,7 +177,7 @@ if ($allowed_files) :
<ul>
<?php
$template_mapping = array();
foreach($themes[$theme]['Stylesheet Files'] as $style_file) {
foreach ( $themes[$theme]['Stylesheet Files'] as $style_file ) {
$description = trim( get_file_description($style_file) );
$style_show = basename($style_file);
$filedesc = ( $description != $style_file ) ? "$description <span class='nonessential'>($style_show)</span>" : "$description";
@ -204,7 +204,7 @@ if ($allowed_files) :
</div>
<?php if ( isset($functions ) && count($functions) ) { ?>
<div id="documentation">
<label for="docs-list">Documentation:</label>
<label for="docs-list"><?php _e('Documentation:') ?></label>
<?php echo $docs_select; ?>
<input type="button" class="button" value=" <?php _e( 'Lookup' ); ?> " onclick="if ( '' != jQuery('#docs-list').val() ) { window.open( 'http://api.wordpress.org/core/handbook/1.0/?function=' + escape( jQuery( '#docs-list' ).val() ) + '&locale=<?php echo urlencode( get_locale() ) ?>&version=<?php echo urlencode( $wp_version ) ?>&redirect=true'); }" />
</div>

View File

@ -372,14 +372,28 @@ function get_themes() {
$template_files[] = "$theme_loc/$stylesheet/$file";
}
}
@ $stylesheet_dir->close();
}
$template_dir = @ dir("$theme_root/$template");
if ( $template_dir ) {
while(($file = $template_dir->read()) !== false) {
if ( !preg_match('|^\.+$|', $file) && preg_match('|\.php$|', $file) )
while ( ($file = $template_dir->read()) !== false ) {
if ( preg_match('|^\.+$|', $file) )
continue;
if ( preg_match('|\.php$|', $file) ) {
$template_files[] = "$theme_loc/$template/$file";
} elseif ( is_dir("$theme_root/$template/$file") ) {
$template_subdir = @ dir("$theme_root/$template/$file");
while ( ($subfile = $template_subdir->read()) !== false ) {
if ( preg_match('|^\.+$|', $subfile) )
continue;
if ( preg_match('|\.php$|', $subfile) )
$template_files[] = "$theme_loc/$template/$file/$subfile";
}
@ $template_subdir->close();
}
}
@ $template_dir->close();
}
$template_dir = dirname($template_files[0]);
@ -1117,4 +1131,27 @@ function add_custom_image_header($header_callback, $admin_header_callback) {
add_action('admin_menu', array(&$GLOBALS['custom_image_header'], 'init'));
}
/**
* Get the basename of a theme.
*
* This method extracts the filename of a theme file from a path
*
* @package WordPress
* @subpackage Plugin
* @since 2.8.0
*
* @access private
*
* @param string $file The filename of a theme file
* @return string The filename relative to the themes folder
*/
function theme_basename($file) {
$file = str_replace('\\','/',$file); // sanitize for Win32 installs
$file = preg_replace('|/+|','/', $file); // remove any duplicate slash
$theme_dir = str_replace('\\','/', get_theme_root()); // sanitize for Win32 installs
$theme_dir = preg_replace('|/+|','/', $theme_dir); // remove any duplicate slash
$file = preg_replace('|^.*/themes/.*?/|','',$file); // get relative path from theme dir
return $file;
}
?>