diff --git a/wp-admin/admin-functions.php b/wp-admin/admin-functions.php
index 3852daf0bd..9a7b284d0b 100644
--- a/wp-admin/admin-functions.php
+++ b/wp-admin/admin-functions.php
@@ -488,4 +488,151 @@ if ( !strstr($_SERVER['HTTP_USER_AGENT'], 'Safari') ) :
endif;
}
+function get_theme_data($theme_file) {
+ $theme_data = implode('', file($theme_file));
+ preg_match("|Theme Name:(.*)|i", $theme_data, $theme_name);
+ preg_match("|Theme URI:(.*)|i", $theme_data, $theme_uri);
+ preg_match("|Description:(.*)|i", $theme_data, $description);
+ preg_match("|Author:(.*)|i", $theme_data, $author_name);
+ preg_match("|Author URI:(.*)|i", $theme_data, $author_uri);
+ preg_match("|Template:(.*)|i", $theme_data, $template);
+ if ( preg_match("|Version:(.*)|i", $theme_data, $version) )
+ $version = $version[1];
+ else
+ $version ='';
+
+ $description = wptexturize($description[1]);
+
+ $name = $theme_name[1];
+ $name = trim($name);
+ $theme = $name;
+ if ('' != $theme_uri && '' != $name) {
+ $theme = __("{$theme}");
+ }
+
+ if ('' == $author_uri) {
+ $author = $author_name[1];
+ } else {
+ $author = __("{$author_name[1]}");
+ }
+
+ return array('Name' => $name, 'Title' => $theme, 'Description' => $description, 'Author' => $author, 'Version' => $version, 'Template' => $template[1]);
+}
+
+function get_themes() {
+ $themes = array();
+ $theme_loc = 'wp-content/themes';
+ $theme_root = ABSPATH . $theme_loc;
+
+ // Files in wp-content/themes directory
+ $themes_dir = @ dir($theme_root);
+ if ($themes_dir) {
+ while(($theme_dir = $themes_dir->read()) !== false) {
+ if (is_dir($theme_root . '/' . $theme_dir)) {
+ $stylish_dir = @ dir($theme_root . '/' . $theme_dir);
+ while(($theme_file = $stylish_dir->read()) !== false) {
+ if ( $theme_file == 'style.css' ) {
+ $theme_files[] = $theme_dir . '/' . $theme_file;
+ }
+ }
+ }
+ }
+ }
+
+ $default_files = array(get_settings('blogfilename'), 'wp-comments.php', 'wp-comments-popup.php', 'wp-comments-post.php', 'wp-footer.php', 'wp-header.php', 'wp-sidebar.php', 'footer.php', 'header.php', 'sidebar.php');
+
+ // Get the files for the default template.
+ $default_template_files = array();
+ {
+ $dirs = array('', 'wp-content');
+ foreach ($dirs as $dir) {
+ $template_dir = @ dir(ABSPATH . $dir);
+ while(($file = $template_dir->read()) !== false) {
+ if ( !preg_match('|^\.+$|', $file) && in_array($file, $default_files))
+ $default_template_files[] = trim("$dir/$file", '/');
+ }
+ }
+ }
+
+ // Get the files for the default stylesheet.
+ $default_stylesheet_files = array();
+ {
+ $stylesheet_dir = @ dir(ABSPATH);
+ while(($file = $stylesheet_dir->read()) !== false) {
+ if ( !preg_match('|^\.+$|', $file) && preg_match('|\.css$|', $file))
+ $default_stylesheet_files[] = "$file";
+ }
+ }
+
+ // The default theme always exists.
+ $themes['Default'] = array('Name' => 'Default', 'Title' => 'Default', 'Description' => 'The default theme', 'Author' => '', 'Version' => '1.3', 'Template' => 'default', 'Stylesheet' => 'default', 'Template Files' => $default_template_files, 'Stylesheet Files' => $default_stylesheet_files);
+
+ if (!$themes_dir || !$theme_files) {
+ return $themes;
+ }
+
+ sort($theme_files);
+
+ foreach($theme_files as $theme_file) {
+ $theme_data = get_theme_data("$theme_root/$theme_file");
+
+ $name = $theme_data['Name'];
+ $title = $theme_data['Title'];
+ $description = wptexturize($theme_data['Description']);
+ $version = $theme_data['Version'];
+ $author = $theme_data['Author'];
+ $template = $theme_data['Template'];
+ $stylesheet = dirname($theme_file);
+
+ if (empty($template)) {
+ if (file_exists(dirname("$theme_root/$theme_file/index.php"))) {
+ $template = dirname($theme_file);
+ } else {
+ continue;
+ }
+ }
+
+ $template = trim($template);
+
+ if (($template != 'default') && (! file_exists("$theme_root/$template/index.php"))) {
+ continue;
+ }
+
+ if (empty($name)) {
+ $name = dirname($theme_file);
+ $title = $name;
+ }
+
+ $stylesheet_files = array();
+ if ($stylesheet != 'default') {
+ $stylesheet_dir = @ dir("$theme_root/$stylesheet");
+ if ($stylesheet_dir) {
+ while(($file = $stylesheet_dir->read()) !== false) {
+ if ( !preg_match('|^\.+$|', $file) && preg_match('|\.css$|', $file) )
+ $stylesheet_files[] = "$theme_loc/$stylesheet/$file";
+ }
+ }
+ } else {
+ $stylesheet_files = $default_stylesheet_files;
+ }
+
+ $template_files = array();
+ if ($template != 'default') {
+ $template_dir = @ dir("$theme_root/$template");
+ if ($template_dir) {
+ while(($file = $template_dir->read()) !== false) {
+ if ( !preg_match('|^\.+$|', $file) && preg_match('|\.php$|', $file) )
+ $template_files[] = "$theme_loc/$template/$file";
+ }
+ }
+ } else {
+ $template_files = $default_template_files;
+ }
+
+ $themes[$name] = array('Name' => $name, 'Title' => $title, 'Description' => $description, 'Author' => $author, 'Version' => $version, 'Template' => $template, 'Stylesheet' => $stylesheet, 'Template Files' => $template_files, 'Stylesheet Files' => $stylesheet_files);
+ }
+
+ return $themes;
+}
+
?>
\ No newline at end of file
diff --git a/wp-admin/menu.php b/wp-admin/menu.php
index 583b87246c..8ecc1a41ad 100644
--- a/wp-admin/menu.php
+++ b/wp-admin/menu.php
@@ -13,8 +13,9 @@ $menu[20] = array(__('Links'), 5, 'link-manager.php');
$menu[25] = array(__('Users'), 3, 'users.php');
$menu[30] = array(__('Options'), 6, 'options-general.php');
$menu[35] = array(__('Plugins'), 8, 'plugins.php');
-$menu[40] = array(__('Templates'), 4, 'templates.php');
-$menu[45] = array(__('Upload'), get_settings('fileupload_minlevel'), 'upload.php');
+$menu[40] = array(__('Presentation'), 8, 'themes.php');
+$menu[45] = array(__('Templates'), 4, 'templates.php');
+$menu[50] = array(__('Upload'), get_settings('fileupload_minlevel'), 'upload.php');
ksort($menu); // So other files can plugin
$submenu['edit.php'][5] = array(__('Posts'), 1, 'edit.php');
@@ -39,6 +40,9 @@ $submenu['options-general.php'][20] = array(__('Discussion'), 5, 'options-discus
$submenu['options-general.php'][25] = array(__('Permalinks'), 5, 'options-permalink.php');
$submenu['options-general.php'][30] = array(__('Miscellaneous'), 5, 'options-misc.php');
+$submenu['themes.php'][5] = array(__('Themes'), 5, 'themes.php');
+$submenu['themes.php'][10] = array(__('Theme Editor'), 5, 'theme-editor.php');
+
$self = preg_replace('|.*/wp-admin/|i', '', $_SERVER['PHP_SELF']);
if (!isset($parent_file)) $parent_file = '';
foreach ($menu as $item) {
diff --git a/wp-admin/theme-editor.php b/wp-admin/theme-editor.php
new file mode 100644
index 0000000000..ea1db0492f
--- /dev/null
+++ b/wp-admin/theme-editor.php
@@ -0,0 +1,199 @@
+ $v) {
+ if (is_array($v)) {
+ $array[$k] = add_magic_quotes($v);
+ } else {
+ $array[$k] = addslashes($v);
+ }
+ }
+ return $array;
+}
+
+function validate_file($file) {
+ if ('..' == substr($file,0,2))
+ die (__('Sorry, can’t edit files with ".." in the name. If you are trying to edit a file in your WordPress home directory, you can just type the name of the file in.'));
+
+ if (':' == substr($file,1,1))
+ die (__('Sorry, can’t call files with their real path.'));
+
+ if ('/' == substr($file,0,1))
+ $file = '.' . $file;
+
+ $file = stripslashes($file);
+ $file = str_replace('../', '', $file);
+
+ return $file;
+}
+
+if (!get_magic_quotes_gpc()) {
+ $_GET = add_magic_quotes($_GET);
+ $_POST = add_magic_quotes($_POST);
+ $_COOKIE = add_magic_quotes($_COOKIE);
+}
+
+$wpvarstoreset = array('action','standalone','redirect','profile','error','warning','a','file', 'theme');
+for ($i=0; $i
You have do not have sufficient permissions to edit themes for this blog.
')); + } + + $themes = get_themes(); + + if (! isset($theme) || empty($theme)) { + $theme = 'Default'; + } + + $stylesheet_files = $themes[$theme]['Stylesheet Files']; + $template_files = $themes[$theme]['Template Files']; + + if ('' == $file) { + $file = $stylesheet_files[0]; + } + + $home = get_settings('home'); + if (($home != '') + && ($home != get_settings('siteurl')) && + ('index.php' == $file || get_settings('blogfilename') == $file || + '.htaccess' == $file)) { + $home_root = parse_url($home); + $home_root = $home_root['path']; + $root = str_replace($_SERVER["PHP_SELF"], '', $_SERVER["PATH_TRANSLATED"]); + $home_root = $root . $home_root; + $real_file = $home_root . '/' . $file; + } else { + $file = validate_file($file); + $real_file = '../' . $file; + } + + if (!is_file($real_file)) + $error = 1; + + if (!$error) { + $f = fopen($real_file, 'r'); + $content = fread($f, filesize($real_file)); + $content = htmlspecialchars($content); + } + + ?> + +' . __('Oops, no such file exists! Double check the name and try again, merci.') . '
%s. The template files are located in %s
. The stylesheet files are located in %s
. %s uses templates from %s. Changes made to the templates will affect both themes.'), $current_theme, $current_template_dir, $current_stylesheet_dir, $current_theme, $current_parent_theme); ?>
%s. The template files are located in %s
. The stylesheet files are located in %s
.'), $current_theme, $current_template_dir, $current_stylesheet_dir); ?>
wp-content/themes directory. Once a theme is installed, you may select it here.'); ?>
+Couldn't open themes directory or there are no themes available."); // TODO: make more helpful +} else { +?> ++ | + | + | + | + |
---|---|---|---|---|
$title | +$version | +$author | +$description | +$action | +