summaryrefslogtreecommitdiffstats
path: root/wp-includes/theme.php
diff options
context:
space:
mode:
authordonncha <donncha@7be80a69-a1ef-0310-a953-fb0f7c49ff36>2006-11-24 16:16:44 +0000
committerdonncha <donncha@7be80a69-a1ef-0310-a953-fb0f7c49ff36>2006-11-24 16:16:44 +0000
commit600b71019494e1c29898a620e58c0d2602f37b74 (patch)
tree21181d77ad4ebbcd42cd883e509c08a568d29514 /wp-includes/theme.php
parent7935d0bd9ef23d32ae29a95bd6c3ea0b6eab2973 (diff)
downloadwordpress-mu-600b71019494e1c29898a620e58c0d2602f37b74.tar.gz
wordpress-mu-600b71019494e1c29898a620e58c0d2602f37b74.tar.xz
wordpress-mu-600b71019494e1c29898a620e58c0d2602f37b74.zip
WP Merge to 4524
git-svn-id: http://svn.automattic.com/wordpress-mu/trunk@810 7be80a69-a1ef-0310-a953-fb0f7c49ff36
Diffstat (limited to 'wp-includes/theme.php')
-rw-r--r--wp-includes/theme.php149
1 files changed, 98 insertions, 51 deletions
diff --git a/wp-includes/theme.php b/wp-includes/theme.php
index d8051da..46f7249 100644
--- a/wp-includes/theme.php
+++ b/wp-includes/theme.php
@@ -1,6 +1,6 @@
<?php
/*
- * Theme/template/stylesheet functions.
+ * Theme/template/stylesheet functions.
*/
function get_stylesheet() {
@@ -14,7 +14,7 @@ function get_stylesheet_directory() {
}
function get_stylesheet_directory_uri() {
- $stylesheet = rawurlencode( get_stylesheet() );
+ $stylesheet = get_stylesheet();
$stylesheet_dir_uri = get_theme_root_uri() . "/$stylesheet";
return apply_filters('stylesheet_directory_uri', $stylesheet_dir_uri, $stylesheet);
}
@@ -32,7 +32,7 @@ function get_locale_stylesheet_uri() {
$locale = get_locale();
if ( file_exists("$dir/$locale.css") )
$stylesheet_uri = "$stylesheet_dir_uri/$locale.css";
- else if ( !empty($wp_locale->text_direction) && file_exists("$dir/{$wp_locale->text_direction}.css") )
+ elseif ( !empty($wp_locale->text_direction) && file_exists("$dir/{$wp_locale->text_direction}.css") )
$stylesheet_uri = "$stylesheet_dir_uri/{$wp_locale->text_direction}.css";
else
$stylesheet_uri = '';
@@ -88,8 +88,7 @@ function get_theme_data($theme_file) {
}
function get_themes() {
- global $wp_themes;
- global $wp_broken_themes;
+ global $wp_themes, $wp_broken_themes;
if ( isset($wp_themes) )
return $wp_themes;
@@ -99,53 +98,70 @@ function get_themes() {
$theme_root = get_theme_root();
$theme_loc = str_replace(ABSPATH, '', $theme_root);
- // Files in wp-content/themes directory
+ // Files in wp-content/themes directory and one subdir down
$themes_dir = @ dir($theme_root);
- if ( $themes_dir ) {
- while(($theme_dir = $themes_dir->read()) !== false) {
- if ( is_dir($theme_root . '/' . $theme_dir) && is_readable($theme_root . '/' . $theme_dir) ) {
- if ( $theme_dir{0} == '.' || $theme_dir == '..' || $theme_dir == 'CVS' ) {
- continue;
+ if ( !$themes_dir )
+ return false;
+
+ while ( ($theme_dir = $themes_dir->read()) !== false ) {
+ if ( is_dir($theme_root . '/' . $theme_dir) && is_readable($theme_root . '/' . $theme_dir) ) {
+ if ( $theme_dir{0} == '.' || $theme_dir == '..' || $theme_dir == 'CVS' )
+ continue;
+ $stylish_dir = @ dir($theme_root . '/' . $theme_dir);
+ $found_stylesheet = false;
+ while ( ($theme_file = $stylish_dir->read()) !== false ) {
+ if ( $theme_file == 'style.css' ) {
+ $theme_files[] = $theme_dir . '/' . $theme_file;
+ $found_stylesheet = true;
+ break;
}
- $stylish_dir = @ dir($theme_root . '/' . $theme_dir);
- $found_stylesheet = false;
- while (($theme_file = $stylish_dir->read()) !== false) {
- if ( $theme_file == 'style.css' ) {
- $theme_files[] = $theme_dir . '/' . $theme_file;
- $found_stylesheet = true;
- break;
+ }
+ if ( !$found_stylesheet ) { // look for themes in that dir
+ $subdir = "$theme_root/$theme_dir";
+ $subdir_name = $theme_dir;
+ $theme_subdir = @dir( $subdir );
+ while ( ($theme_dir = $theme_subdir->read()) !== false ) {
+ if ( is_dir( $subdir . '/' . $theme_dir) && is_readable($subdir . '/' . $theme_dir) ) {
+ if ( $theme_dir{0} == '.' || $theme_dir == '..' || $theme_dir == 'CVS' )
+ continue;
+ $stylish_dir = @ dir($subdir . '/' . $theme_dir);
+ $found_stylesheet = false;
+ while ( ($theme_file = $stylish_dir->read()) !== false ) {
+ if ( $theme_file == 'style.css' ) {
+ $theme_files[] = $subdir_name . '/' . $theme_dir . '/' . $theme_file;
+ $found_stylesheet = true;
+ break;
+ }
+ }
}
}
- if ( !$found_stylesheet ) {
- $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.'));
}
}
}
- if ( !$themes_dir || !$theme_files ) {
+ if ( !$themes_dir || !$theme_files )
return $themes;
- }
sort($theme_files);
- foreach($theme_files as $theme_file) {
- if ( ! is_readable("$theme_root/$theme_file") ) {
+ foreach ( (array) $theme_files as $theme_file ) {
+ if ( !is_readable("$theme_root/$theme_file") ) {
$wp_broken_themes[$theme_file] = array('Name' => $theme_file, 'Title' => $theme_file, 'Description' => __('File not readable.'));
continue;
}
$theme_data = get_theme_data("$theme_root/$theme_file");
- $name = $theme_data['Name'];
- $title = $theme_data['Title'];
+ $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);
+ $version = $theme_data['Version'];
+ $author = $theme_data['Author'];
+ $template = $theme_data['Template'];
+ $stylesheet = dirname($theme_file);
- foreach (array('png', 'gif', 'jpg', 'jpeg') as $ext) {
+ foreach ( array('png', 'gif', 'jpg', 'jpeg') as $ext ) {
if (file_exists("$theme_root/$stylesheet/screenshot.$ext")) {
$screenshot = "screenshot.$ext";
break;
@@ -158,24 +174,28 @@ function get_themes() {
}
if ( empty($template) ) {
- if ( file_exists(dirname("$theme_root/$theme_file/index.php")) ) {
+ if ( file_exists(dirname("$theme_root/$theme_file/index.php")) )
$template = dirname($theme_file);
- } else {
+ else
continue;
- }
}
$template = trim($template);
if ( !file_exists("$theme_root/$template/index.php") ) {
- $wp_broken_themes[$name] = array('Name' => $name, 'Title' => $title, 'Description' => __('Template is missing.'));
- continue;
+ $parent_dir = dirname(dirname($theme_file));
+ if ( file_exists("$theme_root/$parent_dir/$template/index.php") ) {
+ $template = "$parent_dir/$template";
+ } else {
+ $wp_broken_themes[$name] = array('Name' => $name, 'Title' => $title, 'Description' => __('Template is missing.'));
+ continue;
+ }
}
$stylesheet_files = array();
$stylesheet_dir = @ dir("$theme_root/$stylesheet");
if ( $stylesheet_dir ) {
- while(($file = $stylesheet_dir->read()) !== false) {
+ while ( ($file = $stylesheet_dir->read()) !== false ) {
if ( !preg_match('|^\.+$|', $file) && preg_match('|\.css$|', $file) )
$stylesheet_files[] = "$theme_loc/$stylesheet/$file";
}
@@ -222,10 +242,10 @@ function get_themes() {
// Resolve theme dependencies.
$theme_names = array_keys($themes);
- foreach ($theme_names as $theme_name) {
+ foreach ( (array) $theme_names as $theme_name ) {
$themes[$theme_name]['Parent Theme'] = '';
if ( $themes[$theme_name]['Stylesheet'] != $themes[$theme_name]['Template'] ) {
- foreach ($theme_names as $parent_theme_name) {
+ foreach ( (array) $theme_names as $parent_theme_name ) {
if ( ($themes[$parent_theme_name]['Stylesheet'] == $themes[$parent_theme_name]['Template']) && ($themes[$parent_theme_name]['Template'] == $themes[$theme_name]['Template']) ) {
$themes[$theme_name]['Parent Theme'] = $themes[$parent_theme_name]['Name'];
break;
@@ -256,7 +276,7 @@ function get_current_theme() {
$current_theme = 'WordPress Default';
if ( $themes ) {
- foreach ($theme_names as $theme_name) {
+ foreach ( (array) $theme_names as $theme_name ) {
if ( $themes[$theme_name]['Stylesheet'] == $current_stylesheet &&
$themes[$theme_name]['Template'] == $current_template ) {
$current_theme = $themes[$theme_name]['Name'];
@@ -300,7 +320,7 @@ function get_category_template() {
$template = '';
if ( file_exists(TEMPLATEPATH . "/category-" . get_query_var('cat') . '.php') )
$template = TEMPLATEPATH . "/category-" . get_query_var('cat') . '.php';
- else if ( file_exists(TEMPLATEPATH . "/category.php") )
+ elseif ( file_exists(TEMPLATEPATH . "/category.php") )
$template = TEMPLATEPATH . "/category.php";
return apply_filters('category_template', $template);
@@ -315,7 +335,7 @@ function get_home_template() {
if ( file_exists(TEMPLATEPATH . "/home.php") )
$template = TEMPLATEPATH . "/home.php";
- else if ( file_exists(TEMPLATEPATH . "/index.php") )
+ elseif ( file_exists(TEMPLATEPATH . "/index.php") )
$template = TEMPLATEPATH . "/index.php";
return apply_filters('home_template', $template);
@@ -330,9 +350,9 @@ function get_page_template() {
if ( 'default' == $template )
$template = '';
- if ( ! empty($template) && file_exists(TEMPLATEPATH . "/$template") )
+ if ( !empty($template) && file_exists(TEMPLATEPATH . "/$template") )
$template = TEMPLATEPATH . "/$template";
- else if ( file_exists(TEMPLATEPATH . "/page.php") )
+ elseif ( file_exists(TEMPLATEPATH . "/page.php") )
$template = TEMPLATEPATH . "/page.php";
else
$template = '';
@@ -374,14 +394,13 @@ function get_comments_popup_template() {
return apply_filters('comments_popup_template', $template);
}
-function load_template($file) {
+function load_template($_template_file) {
global $posts, $post, $wp_did_header, $wp_did_template_redirect, $wp_query,
$wp_rewrite, $wpdb, $wp_version, $wp, $id, $comment;
- if( is_array( $wp_query->query_vars ) )
- extract($wp_query->query_vars);
+ extract($wp_query->query_vars, EXTR_SKIP);
- require_once($file);
+ require_once($_template_file);
}
function locale_stylesheet() {
@@ -396,14 +415,14 @@ function validate_current_theme() {
if ( defined('WP_INSTALLING') )
return true;
- if ((get_template() != 'default') && (!file_exists(get_template_directory() . '/index.php'))) {
+ if ( get_template() != 'default' && !file_exists(get_template_directory() . '/index.php') ) {
update_option('template', 'default');
update_option('stylesheet', 'default');
do_action('switch_theme', 'Default');
return false;
}
- if ((get_stylesheet() != 'default') && (!file_exists(get_template_directory() . '/style.css'))) {
+ if ( get_stylesheet() != 'default' && !file_exists(get_template_directory() . '/style.css') ) {
update_option('template', 'default');
update_option('stylesheet', 'default');
do_action('switch_theme', 'Default');
@@ -413,4 +432,32 @@ function validate_current_theme() {
return true;
}
+function get_theme_mod($name, $default = false) {
+ $theme = get_current_theme();
+
+ $mods = get_option("mods_$theme");
+
+ if ( isset($mods[$name]) )
+ return $mods[$name];
+
+ return sprintf($default, get_template_directory_uri());
+}
+
+function set_theme_mod($name, $value) {
+ $theme = get_current_theme();
+
+ $mods = get_option("mods_$theme");
+
+ $mods[$name] = $value;
+
+ update_option("mods_$theme", $mods);
+ wp_cache_delete("mods_$theme", 'options');
+}
+
+function remove_theme_mods() {
+ $theme = get_current_theme();
+
+ delete_option("mods_$theme");
+}
+
?>