Use opendir instead of dir. Props nbachiyski. fixes #4450

git-svn-id: https://develop.svn.wordpress.org/trunk@5867 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ryan Boren 2007-08-14 02:58:33 +00:00
parent 9d8324b07b
commit 3e5d2230d2
4 changed files with 28 additions and 19 deletions

View File

@ -14,9 +14,9 @@ require_once ('admin-header.php');
// Load all importers so that they can register. // Load all importers so that they can register.
$import_loc = 'wp-admin/import'; $import_loc = 'wp-admin/import';
$import_root = ABSPATH.$import_loc; $import_root = ABSPATH.$import_loc;
$imports_dir = @ dir($import_root); $imports_dir = @ opendir($import_root);
if ($imports_dir) { if ($imports_dir) {
while (($file = $imports_dir->read()) !== false) { while (($file = readdir($imports_dir) !== false) {
if ($file{0} == '.') { if ($file{0} == '.') {
continue; continue;
} elseif (substr($file, -4) == '.php') { } elseif (substr($file, -4) == '.php') {
@ -24,6 +24,7 @@ if ($imports_dir) {
} }
} }
} }
@closedir($imports_dir);
$importers = get_importers(); $importers = get_importers();

View File

@ -42,15 +42,15 @@ function get_plugins() {
$plugin_root = ABSPATH . PLUGINDIR; $plugin_root = ABSPATH . PLUGINDIR;
// Files in wp-content/plugins directory // Files in wp-content/plugins directory
$plugins_dir = @ dir( $plugin_root); $plugins_dir = @ opendir( $plugin_root);
if ( $plugins_dir ) { if ( $plugins_dir ) {
while (($file = $plugins_dir->read() ) !== false ) { while (($file = readdir( $plugins_dir ) ) !== false ) {
if ( substr($file, 0, 1) == '.' ) if ( substr($file, 0, 1) == '.' )
continue; continue;
if ( is_dir( $plugin_root.'/'.$file ) ) { if ( is_dir( $plugin_root.'/'.$file ) ) {
$plugins_subdir = @ dir( $plugin_root.'/'.$file ); $plugins_subdir = @ opendir( $plugin_root.'/'.$file );
if ( $plugins_subdir ) { if ( $plugins_subdir ) {
while (($subfile = $plugins_subdir->read() ) !== false ) { while (($subfile = readdir( $plugins_subdir ) ) !== false ) {
if ( substr($subfile, 0, 1) == '.' ) if ( substr($subfile, 0, 1) == '.' )
continue; continue;
if ( substr($subfile, -4) == '.php' ) if ( substr($subfile, -4) == '.php' )
@ -63,6 +63,8 @@ function get_plugins() {
} }
} }
} }
@closedir( $plugins_dir );
@closedir( $plugins_subdir );
if ( !$plugins_dir || !$plugin_files ) if ( !$plugins_dir || !$plugin_files )
return $wp_plugins; return $wp_plugins;

View File

@ -1103,9 +1103,9 @@ function make_site_theme_from_default($theme_name, $template) {
// Copy files from the default theme to the site theme. // Copy files from the default theme to the site theme.
//$files = array('index.php', 'comments.php', 'comments-popup.php', 'footer.php', 'header.php', 'sidebar.php', 'style.css'); //$files = array('index.php', 'comments.php', 'comments-popup.php', 'footer.php', 'header.php', 'sidebar.php', 'style.css');
$theme_dir = @ dir("$default_dir"); $theme_dir = @ opendir("$default_dir");
if ($theme_dir) { if ($theme_dir) {
while(($theme_file = $theme_dir->read()) !== false) { while(($theme_file = readdir( $theme_dir )) !== false) {
if (is_dir("$default_dir/$theme_file")) if (is_dir("$default_dir/$theme_file"))
continue; continue;
if (! @copy("$default_dir/$theme_file", "$site_dir/$theme_file")) if (! @copy("$default_dir/$theme_file", "$site_dir/$theme_file"))
@ -1113,6 +1113,7 @@ function make_site_theme_from_default($theme_name, $template) {
chmod("$site_dir/$theme_file", 0777); chmod("$site_dir/$theme_file", 0777);
} }
} }
@closedir($theme_dir);
// Rewrite the theme header. // Rewrite the theme header.
$stylelines = explode("\n", implode('', file("$site_dir/style.css"))); $stylelines = explode("\n", implode('', file("$site_dir/style.css")));
@ -1136,9 +1137,9 @@ function make_site_theme_from_default($theme_name, $template) {
return false; return false;
} }
$images_dir = @ dir("$default_dir/images"); $images_dir = @ opendir("$default_dir/images");
if ($images_dir) { if ($images_dir) {
while(($image = $images_dir->read()) !== false) { while(($image = readdir($images_dir)) !== false) {
if (is_dir("$default_dir/images/$image")) if (is_dir("$default_dir/images/$image"))
continue; continue;
if (! @copy("$default_dir/images/$image", "$site_dir/images/$image")) if (! @copy("$default_dir/images/$image", "$site_dir/images/$image"))
@ -1146,6 +1147,7 @@ function make_site_theme_from_default($theme_name, $template) {
chmod("$site_dir/images/$image", 0777); chmod("$site_dir/images/$image", 0777);
} }
} }
@closedir($images_dir);
} }
// Create a site theme from the default theme. // Create a site theme from the default theme.
@ -1232,4 +1234,4 @@ function maybe_disable_automattic_widgets() {
} }
} }
?> ?>

View File

@ -118,46 +118,50 @@ function get_themes() {
$theme_loc = str_replace(ABSPATH, '', $theme_root); $theme_loc = str_replace(ABSPATH, '', $theme_root);
// Files in wp-content/themes directory and one subdir down // Files in wp-content/themes directory and one subdir down
$themes_dir = @ dir($theme_root); $themes_dir = @ opendir($theme_root);
if ( !$themes_dir ) if ( !$themes_dir )
return false; return false;
while ( ($theme_dir = $themes_dir->read()) !== false ) { while ( ($theme_dir = readdir($themes_dir)) !== false ) {
if ( is_dir($theme_root . '/' . $theme_dir) && is_readable($theme_root . '/' . $theme_dir) ) { if ( is_dir($theme_root . '/' . $theme_dir) && is_readable($theme_root . '/' . $theme_dir) ) {
if ( $theme_dir{0} == '.' || $theme_dir == '..' || $theme_dir == 'CVS' ) if ( $theme_dir{0} == '.' || $theme_dir == '..' || $theme_dir == 'CVS' )
continue; continue;
$stylish_dir = @ dir($theme_root . '/' . $theme_dir); $stylish_dir = @ opendir($theme_root . '/' . $theme_dir);
$found_stylesheet = false; $found_stylesheet = false;
while ( ($theme_file = $stylish_dir->read()) !== false ) { while ( ($theme_file = readdir($stylish_dir)) !== false ) {
if ( $theme_file == 'style.css' ) { if ( $theme_file == 'style.css' ) {
$theme_files[] = $theme_dir . '/' . $theme_file; $theme_files[] = $theme_dir . '/' . $theme_file;
$found_stylesheet = true; $found_stylesheet = true;
break; break;
} }
} }
@closedir($stylish_dir);
if ( !$found_stylesheet ) { // look for themes in that dir if ( !$found_stylesheet ) { // look for themes in that dir
$subdir = "$theme_root/$theme_dir"; $subdir = "$theme_root/$theme_dir";
$subdir_name = $theme_dir; $subdir_name = $theme_dir;
$theme_subdir = @dir( $subdir ); $theme_subdir = @ opendir( $subdir );
while ( ($theme_dir = $theme_subdir->read()) !== false ) { while ( ($theme_dir = readdir($theme_subdir)) !== false ) {
if ( is_dir( $subdir . '/' . $theme_dir) && is_readable($subdir . '/' . $theme_dir) ) { if ( is_dir( $subdir . '/' . $theme_dir) && is_readable($subdir . '/' . $theme_dir) ) {
if ( $theme_dir{0} == '.' || $theme_dir == '..' || $theme_dir == 'CVS' ) if ( $theme_dir{0} == '.' || $theme_dir == '..' || $theme_dir == 'CVS' )
continue; continue;
$stylish_dir = @ dir($subdir . '/' . $theme_dir); $stylish_dir = @ opendir($subdir . '/' . $theme_dir);
$found_stylesheet = false; $found_stylesheet = false;
while ( ($theme_file = $stylish_dir->read()) !== false ) { while ( ($theme_file = readdir($stylish_dir)) !== false ) {
if ( $theme_file == 'style.css' ) { if ( $theme_file == 'style.css' ) {
$theme_files[] = $subdir_name . '/' . $theme_dir . '/' . $theme_file; $theme_files[] = $subdir_name . '/' . $theme_dir . '/' . $theme_file;
$found_stylesheet = true; $found_stylesheet = true;
break; break;
} }
} }
@closedir($stylish_dir);
} }
} }
@closedir($theme_subdir);
$wp_broken_themes[$theme_dir] = array('Name' => $theme_dir, 'Title' => $theme_dir, 'Description' => __('Stylesheet is missing.')); $wp_broken_themes[$theme_dir] = array('Name' => $theme_dir, 'Title' => $theme_dir, 'Description' => __('Stylesheet is missing.'));
} }
} }
} }
@closedir($theme_dir);
if ( !$themes_dir || !$theme_files ) if ( !$themes_dir || !$theme_files )
return $themes; return $themes;