From fec36ee655e350f37c2e1f7eb5aef06e2801f0d8 Mon Sep 17 00:00:00 2001
From: rboren
Date: Sat, 11 Sep 2004 16:12:40 +0000
Subject: [PATCH] Themes.
git-svn-id: http://svn.automattic.com/wordpress/trunk@1638 1a063a9b-81f0-0310-95a4-ce76da25c4cd
---
wp-admin/admin-functions.php | 147 +++++++++++++++
wp-admin/menu.php | 8 +-
wp-admin/theme-editor.php | 199 +++++++++++++++++++++
wp-admin/themes.php | 125 +++++++++++++
wp-admin/upgrade-schema.php | 2 +
wp-blog-header.php | 64 +++++--
wp-includes/template-functions-general.php | 16 ++
7 files changed, 541 insertions(+), 20 deletions(-)
create mode 100644 wp-admin/theme-editor.php
create mode 100644 wp-admin/themes.php
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; $iYou have do not have sufficient permissions to edit templates for this blog.
'));
+ }
+
+ $newcontent = stripslashes($_POST['newcontent']);
+ $file = $_POST['file'];
+ $file = validate_file($file);
+ $real_file = '../' . $file;
+ if (is_writeable($real_file)) {
+ $f = fopen($real_file, 'w+');
+ fwrite($f, $newcontent);
+ fclose($f);
+ header("Location: theme-editor.php?file=$file&a=te");
+ } else {
+ header("Location: theme-editor.php?file=$file");
+ }
+
+ exit();
+
+break;
+
+default:
+
+ require_once('admin-header.php');
+ update_option('recently_edited', array(1, 2, 3) );
+ if ($user_level <= 5) {
+ die(__('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);
+ }
+
+ ?>
+
+
+
+
+
+
+
+
+ " . sprintf(__('Editing
%s'), $file) . "";
+
+ if (!$error) {
+ ?>
+
+
' . __('Oops, no such file exists! Double check the name and try again, merci.') . '
';
+ }
+ ?>
+
+
+
+
%s theme files:'), $theme) ?>
+
+
+
+
+
diff --git a/wp-admin/themes.php b/wp-admin/themes.php
new file mode 100644
index 0000000000..8e9d662b0c
--- /dev/null
+++ b/wp-admin/themes.php
@@ -0,0 +1,125 @@
+
+
+
+
+
+ %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 {
+?>
+
+
+ |
+ |
+ |
+ |
+ |
+
+" . __('Active Theme') . '';
+ } else {
+ $action = "" . __('Select') . '';
+ }
+
+ $theme = ('class="alternate"' == $theme) ? '' : 'class="alternate"';
+ echo "
+
+ $title |
+ $version |
+ $author |
+ $description |
+ $action |
+
";
+ }
+?>
+
+
+
+
+
+
\ No newline at end of file
diff --git a/wp-admin/upgrade-schema.php b/wp-admin/upgrade-schema.php
index 5a1e130186..95ae062e7a 100644
--- a/wp-admin/upgrade-schema.php
+++ b/wp-admin/upgrade-schema.php
@@ -215,6 +215,8 @@ function populate_options() {
add_option('default_email_category', 1, 'Posts by email go to this category');
add_option('recently_edited');
add_option('use_linksupdate', 0);
+ add_option('template', 'default');
+ add_option('stylesheet', 'default');
// Delete unused options
$unusedoptions = array ('blodotgsping_url', 'bodyterminator', 'emailtestonly', 'phoneemail_separator', 'smilies_directory', 'subjectprefix', 'use_bbcode', 'use_blodotgsping', 'use_phoneemail', 'use_quicktags', 'use_weblogsping', 'weblogs_cache_file', 'use_preview', 'use_htmltrans', 'smilies_directory', 'rss_language', 'fileupload_allowedusers', 'use_phoneemail', 'default_post_status', 'default_post_category', 'archive_mode', 'time_difference', 'links_minadminlevel', 'links_use_adminlevels', 'links_rating_type', 'links_rating_char', 'links_rating_ignore_zero', 'links_rating_single_image', 'links_rating_image0', 'links_rating_image1', 'links_rating_image2', 'links_rating_image3', 'links_rating_image4', 'links_rating_image5', 'links_rating_image6', 'links_rating_image7', 'links_rating_image8', 'links_rating_image9', 'weblogs_cacheminutes', 'comment_allowed_tags', 'search_engine_friendly_urls');
diff --git a/wp-blog-header.php b/wp-blog-header.php
index 56cd6eae32..f601bf58b8 100644
--- a/wp-blog-header.php
+++ b/wp-blog-header.php
@@ -66,6 +66,10 @@ if ((isset($_GET['error']) && $_GET['error'] == '404') ||
unset($_GET['error']);
}
+ if (isset($error)) {
+ unset($error);
+ }
+
break;
}
}
@@ -101,7 +105,9 @@ if (1 == $tb) {
// Sending HTTP headers
-if ( !isset($doing_rss) || !$doing_rss ) {
+if (is_404()) {
+ header("HTTP/1.x 404 Not Found");
+} else if ( !isset($doing_rss) || !$doing_rss ) {
@header ('X-Pingback: '. get_settings('siteurl') . '/xmlrpc.php');
} else {
// We're showing a feed, so WP is indeed the only thing that last changed
@@ -183,46 +189,63 @@ if (1 == count($posts)) {
$wp_did_header = true;
endif;
+$wp_template = get_settings('template');
+
+if ($wp_template == 'default') {
+ $wp_template = '';
+}
+
+if (! empty($wp_template)) {
+ $wp_template = "themes/$wp_template/";
+}
+
// Template redirection
-if (is_single() && (! isset($wp_did_single)) &&
- file_exists(ABSPATH . 'wp-content/single.php')) {
+if ($pagenow != get_settings('blogfilename')) {
+ // Noop.
+} else if (is_home() && (! isset($wp_did_home)) &&
+ file_exists(ABSPATH . "wp-content/${wp_template}index.php")) {
+ $wp_did_home = true;
+ include(ABSPATH . "wp-content/${wp_template}index.php");
+ exit;
+} else if (is_single() && (! isset($wp_did_single)) &&
+ file_exists(ABSPATH . "wp-content/${wp_template}single.php")) {
$wp_did_single = true;
- include(ABSPATH . 'wp-content/single.php');
+ include(ABSPATH . "wp-content/${wp_template}single.php");
exit;
} else if (is_page() && (! isset($wp_did_page)) &&
- file_exists(ABSPATH . 'wp-content/page.php')) {
+ file_exists(ABSPATH . "wp-content/${wp_template}page.php")) {
$wp_did_page = true;
- include(ABSPATH . 'wp-content/page.php');
+ include(ABSPATH . "wp-content/${wp_template}page.php");
exit;
} else if (is_category() && (! isset($wp_did_category)) &&
- file_exists(ABSPATH . 'wp-content/category.php')) {
+ file_exists(ABSPATH . "wp-content/${wp_template}category.php")) {
$wp_did_category = true;
- include(ABSPATH . 'wp-content/category.php');
+ include(ABSPATH . "wp-content/${wp_template}category.php");
exit;
} else if (is_author() && (! isset($wp_did_author)) &&
- file_exists(ABSPATH . 'wp-content/author.php')) {
+ file_exists(ABSPATH . "wp-content/${wp_template}author.php")) {
$wp_did_author = true;
- include(ABSPATH . 'wp-content/author.php');
+ include(ABSPATH . "wp-content/${wp_template}author.php");
exit;
} else if (is_date() && (! isset($wp_did_date)) &&
- file_exists(ABSPATH . 'wp-content/date.php')) {
+ file_exists(ABSPATH . "wp-content/${wp_template}date.php")) {
$wp_did_date = true;
- include(ABSPATH . 'wp-content/date.php');
+ include(ABSPATH . "wp-content/${wp_template}date.php");
exit;
} else if (is_archive() && (! isset($wp_did_archive)) &&
- file_exists(ABSPATH . 'wp-content/archive.php')) {
+ file_exists(ABSPATH . "wp-content/${wp_template}archive.php")) {
$wp_did_archive = true;
- include(ABSPATH . 'wp-content/archive.php');
+ include(ABSPATH . "wp-content/${wp_template}archive.php");
exit;
} else if (is_search() && (! isset($wp_did_search)) &&
- file_exists(ABSPATH . 'wp-content/search.php')) {
+ file_exists(ABSPATH . "wp-content/${wp_template}search.php")) {
$wp_did_search = true;
- include(ABSPATH . 'wp-content/search.php');
+ include(ABSPATH . "wp-content/${wp_template}search.php");
exit;
} else if (is_404() && (! isset($wp_did_404)) &&
- file_exists(ABSPATH . 'wp-content/404.php')) {
+ file_exists(ABSPATH . "wp-content/${wp_template}404.php")) {
$wp_did_404 = true;
- include(ABSPATH . 'wp-content/404.php');
+ include(ABSPATH . "wp-content/${wp_template}404.php");
exit;
} else if (is_feed() && $pagenow != 'wp-feed.php') {
include(dirname(__FILE__) . '/wp-feed.php');
@@ -230,6 +253,11 @@ if (is_single() && (! isset($wp_did_single)) &&
} else if ($pagenow != 'wp-trackback.php' && $tb == 1) {
include(dirname(__FILE__) . '/wp-trackback.php');
exit;
+} else if ((! isset($wp_did_home)) && file_exists(ABSPATH . "wp-content/${wp_template}index.php"))
+{
+ $wp_did_home = true;
+ include(ABSPATH . "wp-content/${wp_template}index.php");
+ exit;
}
if ($pagenow != 'post.php' && $pagenow != 'edit.php') {
diff --git a/wp-includes/template-functions-general.php b/wp-includes/template-functions-general.php
index e843a6c418..7c9f3efd5b 100644
--- a/wp-includes/template-functions-general.php
+++ b/wp-includes/template-functions-general.php
@@ -77,6 +77,22 @@ function get_bloginfo($show='') {
case 'pingback_url':
$output = get_settings('siteurl') .'/xmlrpc.php';
break;
+ case 'stylesheet_url':
+ $output = get_settings('stylesheet');;
+ if (empty($output) || $output == 'default') {
+ $output = get_settings('home') . "/wp-layout.css";
+ } else {
+ $output = get_settings('home') . "/wp-content/themes/$output/style.css";
+ }
+ break;
+ case 'template_url':
+ $output = get_settings('template');;
+ if (empty($output) || $output == 'default') {
+ $output = get_settings('home');
+ } else {
+ $output = get_settings('home') . "/wp-content/themes/$output";
+ }
+ break;
case 'admin_email':
$output = get_settings('admin_email');
break;