Commit 6ea5c56d authored by Dries's avatar Dries
Browse files

- Theme system changes.  Please consult http://drupal.org/node/view/9576 for details.
parent 6e145281
......@@ -3,7 +3,7 @@
#
# Protect files and directories from prying eyes:
<Files ~ "(\.(conf|inc|module|pl|sh|sql|theme)|Entries|Repositories|Root|scripts|updates)$">
<Files ~ "(\.(conf|inc|module|pl|sh|sql|theme|engine|xtmpl)|Entries|Repositories|Root|scripts|updates)$">
order deny,allow
deny from all
</Files>
......
......@@ -732,7 +732,8 @@ INSERT INTO system VALUES ('modules/node.module','node','module','',1,0,0);
INSERT INTO system VALUES ('modules/page.module','page','module','',1,0,0);
INSERT INTO system VALUES ('modules/story.module','story','module','',1,0,0);
INSERT INTO system VALUES ('modules/taxonomy.module','taxonomy','module','',1,0,0);
INSERT INTO system VALUES ('themes/xtemplate/xtemplate.theme','xtemplate','theme','Internet explorer, Netscape, Opera',1,0,0);
INSERT INTO system VALUES ('themes/bluemarine/xtemplate.xtmpl','bluemarine','theme','themes/engines/xtemplate/xtemplate.engine',1,0,0);
INSERT INTO system VALUES ('themes/engines/xtemplate/xtemplate.engine','xtemplate','theme_engine','',1,0,0);
INSERT INTO users (uid, name, mail) VALUES ('0', '', '');
INSERT INTO users_roles (uid, rid) VALUES (0, 1);
......@@ -743,7 +744,7 @@ INSERT INTO role (rid, name) VALUES (2, 'authenticated user');
INSERT INTO permission VALUES (2,'access comments, access content, post comments, post comments without approval',0);
REPLACE variable SET name='update_start', value='s:10:"2004-02-21;"';
REPLACE variable SET name='theme_default', value='s:9:"xtemplate";';
REPLACE variable SET name='theme_default', value='s:10:"bluemarine";';
REPLACE blocks SET module = 'user', delta = '0', status = '1';
REPLACE blocks SET module = 'user', delta = '1', status = '1';
......
......@@ -717,10 +717,11 @@ INSERT INTO system VALUES ('modules/node.module','node','module','',1,0,0);
INSERT INTO system VALUES ('modules/page.module','page','module','',1,0,0);
INSERT INTO system VALUES ('modules/story.module','story','module','',1,0,0);
INSERT INTO system VALUES ('modules/taxonomy.module','taxonomy','module','',1,0,0);
INSERT INTO system VALUES ('themes/xtemplate/xtemplate.theme','xtemplate','theme','Internet explorer, Netscape, Opera',1,0,0);
INSERT INTO system VALUES ('themes/bluemarine/xtemplate.xtmpl','bluemarine','theme','themes/engines/xtemplate/xtemplate.engine',1,0,0);
INSERT INTO system VALUES ('themes/engines/xtemplate/xtemplate.engine','xtemplate','theme_engine','',1,0,0);
INSERT INTO variable(name,value) VALUES('update_start', 's:10:"2004-02-21";');
INSERT INTO variable(name,value) VALUES('theme_default','s:9:"xtemplate";');
INSERT INTO variable(name,value) VALUES('theme_default','s:10:"bluemarine";');
INSERT INTO users(uid,name,mail) VALUES(0,'','');
INSERT INTO users_roles(uid,rid) VALUES(0, 1);
......
......@@ -74,7 +74,8 @@
"2004-08-10" => "update_100",
"2004-08-11" => "update_101",
"2004-08-12" => "update_102",
"2004-08-17" => "update_103"
"2004-08-17" => "update_103",
"2004-08-19" => "update_104"
);
function update_32() {
......@@ -1522,6 +1523,34 @@ function update_103() {
return $ret;
}
function update_104() {
$ret = array();
if (variable_get('theme_default', 'xtemplate') == 'chameleon') {
$ret[] = update_sql("DELETE FROM {system} WHERE name = 'chameleon'");
$ret[] = update_sql("INSERT INTO system VALUES ('themes/chameleon/chameleon.theme','chameleon','theme','',1,0,0)");
$ret[] = update_sql("INSERT INTO system VALUES ('themes/chameleon/marvin/style.css','marvin','theme','themes/chameleon/chameleon.theme',1,0,0)");
if (variable_get("chameleon_stylesheet", "themes/chameleon/pure/chameleon.css") == "themes/chameleon/marvin/chameleon.css") {
variable_set('theme_default', 'chameleon/marvin');
}
else {
variable_set('theme_default', 'chameleon');
}
}
elseif (variable_get('theme_default', 'xtemplate') == 'xtemplate') {
$ret[] = update_sql("DELETE FROM {system} WHERE name = 'xtemplate'");
$ret[] = update_sql("INSERT INTO system VALUES ('themes/bluemarine/bluemarine.theme','bluemarine','theme','themes/engines/xtemplate/xtemplate.engine',1,0,0)");
$ret[] = update_sql("INSERT INTO system VALUES ('themes/pushbutton/pushbutton.theme','pushbutton','theme','themes/engines/xtemplate/xtemplate.engine',1,0,0)");
$ret[] = update_sql("INSERT INTO system VALUES ('themes/engines/xtemplate/xtemplate.engine','xtemplate','theme_engine','',1,0,0)");
if (variable_get('xtemplate_template', 'default') == 'pushbutton') {
variable_set('theme_default', 'pushbutton');
}
else {
variable_set('theme_default', 'bluemarine');
}
}
return $ret;
}
function update_sql($sql) {
$edit = $_POST["edit"];
$result = db_query($sql);
......
......@@ -87,9 +87,7 @@ function drupal_get_html_head() {
$output = "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n";
$output .= "<base href=\"$base_url/\" />\n";
$output .= "<style type=\"text/css\" media=\"all\">\n";
$output .= "@import url(misc/drupal.css);\n";
$output .= "</style>\n";
$output .= theme('stylesheet_import', 'misc/drupal.css');
return $output . drupal_set_html_head();
}
......
......@@ -437,7 +437,7 @@ function file_scan_directory($dir, $mask, $nomask = array('.', '..', 'CVS'), $ca
}
elseif (ereg($mask, $file)) {
$name = basename($file);
$files["$dir/$file"]->path = "$dir/$file";
$files["$dir/$file"]->filename = "$dir/$file";
$files["$dir/$file"]->name = substr($name, 0, strrpos($name, '.'));
if ($callback) {
$callback("$dir/$file");
......
......@@ -33,16 +33,52 @@ function theme_help($section) {
* The name of the currently selected theme.
*/
function init_theme() {
global $user;
global $user, $custom_theme, $theme_engine, $theme_key;
$themes = list_themes();
// Only select the user selected theme if it is available in the
// list of enabled themes.
$theme = $user->theme && $themes[$user->theme] ? $user->theme : variable_get('theme_default', 0);
$theme = $user->theme && $themes[$user->theme] ? $user->theme : variable_get('theme_default', 'bluemarine');
include_once($themes[$theme]->filename);
// Allow modules to override the present theme... only select custom theme
// if it is available in the list of enabled themes.
$theme = $custom_theme && $themes[$custom_theme] ? $custom_theme : $theme;
// Store the identifier for retrieving theme settings with.
$theme_key = $theme;
// If we're using a style, load its appropriate theme,
// which is stored in the style's description field.
// Also load the stylesheet using drupal_set_html_head().
// Otherwise, load the theme.
if (strpos($themes[$theme]->filename, '.css')) {
// File is a style; put it in the html_head buffer
// Set theme to its template/theme
drupal_set_html_head(theme('stylesheet_import', $themes[$theme]->filename));
$theme = $themes[$theme]->description;
}
else {
// File is a template/theme
// Put the css with the same name in html_head, if it exists
if (file_exists($stylesheet = dirname($themes[$theme]->filename) .'/style.css')) {
drupal_set_html_head(theme('stylesheet_import', $stylesheet));
}
}
if (strpos($themes[$theme]->filename, '.theme')) {
// file is a theme; include it
include_once($themes[$theme]->filename);
}
elseif (strpos($themes[$theme]->description, '.engine')) {
// file is a template; include its engine
include_once($themes[$theme]->description);
$theme_engine = basename($themes[$theme]->description, '.engine');
if (function_exists($theme_engine .'_init')) {
call_user_func($theme_engine .'_init', $themes[$theme]);
}
}
return $theme;
}
......@@ -74,13 +110,42 @@ function list_themes($refresh = FALSE) {
return $list;
}
/**
* Provides a list of currently available theme engines
*
* @param $refresh
* Whether to reload the list of themes from the database.
* @return
* An array of the currently available theme engines.
*/
function list_theme_engines($refresh = FALSE) {
static $list;
if ($refresh) {
unset($list);
}
if (!$list) {
$list = array();
$result = db_query("SELECT * FROM {system} where type = 'theme_engine' AND status = '1' ORDER BY name");
while ($engine = db_fetch_object($result)) {
if (file_exists($engine->filename)) {
$list[$engine->name] = $engine;
}
}
}
return $list;
}
/**
* Generate the themed representation of a Drupal object.
*
* All requests for themed functions must go through this function. It examines
* the request and routes it to the appropriate theme function. If the current
* theme does not implement the requested function, then the base theme function
* is called.
* theme does not implement the requested function, then the current theme
* engine is checked. If neither the engine nor theme implement the requested
* function, then the base theme function is called.
*
* For example, to retrieve the HTML that is output by theme_page($output), a
* module should call theme('page', $output).
......@@ -94,14 +159,21 @@ function list_themes($refresh = FALSE) {
*/
function theme() {
global $theme;
global $theme_engine;
$args = func_get_args();
$function = array_shift($args);
if (($theme != '') && (function_exists($theme .'_'. $function))) {
if (($theme != '') && function_exists($theme .'_'. $function)) {
// call theme function
return call_user_func_array($theme .'_'. $function, $args);
}
elseif (($theme != '') && isset($theme_engine) && function_exists($theme_engine .'_'. $function)) {
// call engine function
return call_user_func_array($theme_engine .'_'. $function, $args);
}
elseif (function_exists('theme_'. $function)){
// call Drupal function
return call_user_func_array('theme_'. $function, $args);
}
}
......@@ -117,6 +189,113 @@ function path_to_theme() {
return dirname($themes[$theme]->filename);
}
/**
* Retrieve an associative array containing the settings for a theme.
*
* The final settings are arrived at by merging the default settings,
* the site-wide settings, and the settings defined for the specific theme.
* If no $key was specified, only the site-wide theme defaults are retrieved.
*
* The default values for each of settings are also defined in this function.
* To add new settings, add their default values here, and then add form elements
* to system_theme_settings() in system.module.
*
* @param $key
* The template/style value for a given theme.
*
* @return
* An associative array containing theme settings.
*/
function drupal_get_theme_settings($key = NULL) {
$defaults = array(
'primary_links' => '',
'secondary_links' => l('edit secondary links', 'admin/themes/settings'),
'mission' => '',
'default_logo' => 1,
'logo_path' => '',
'toggle_logo' => 1,
'toggle_name' => 1,
'toggle_search' => 1,
'toggle_slogan' => 0,
'toggle_mission' => 1,
'toggle_primary_links' => 1,
'toggle_secondary_links' => 1,
'toggle_node_user_picture' => 0,
'toggle_comment_user_picture' => 0,
);
foreach (node_list() as $type) {
$defaults['toggle_node_info_' . $type] = 1;
}
$settings = array_merge($defaults, variable_get('theme_settings', array()));
if ($key) {
$settings = array_merge($settings, variable_get(str_replace('/', '_', 'theme_'. $key .'_settings'), array()));
}
return $settings;
}
/**
* Retrieve a setting for the current theme.
* This function is designed for use from within themes & engines
* to determine theme settings made in the admin interface.
*
* Caches values for speed (use $refresh = TRUE to refresh cache)
*
* @param $setting_name
* The name of the setting to be retrieved.
*
* @param $refresh
* Whether to reload the cache of settings.
*
* @return
* The value of the requested setting, NULL if the setting does not exist.
*/
function drupal_get_theme_setting($setting_name, $refresh = FALSE) {
global $theme_key;
static $settings;
if (empty($settings) || $refresh) {
$settings = drupal_get_theme_settings($theme_key);
$themes = list_themes();
$theme_object = $themes[$theme_key];
if ($settings['mission'] == '') {
$settings['mission'] = variable_get('site_mission', '');
}
if (!$settings['toggle_mission']) {
$settings['mission'] = '';
}
if ($settings['toggle_logo']) {
if ($settings['default_logo']) {
$settings['logo'] = dirname($theme_object->filename) .'/logo.png';
}
elseif ($settings['logo_path']) {
$settings['logo'] = $settings['logo_path'];
}
}
if ($settings['toggle_primary_links']) {
if (!$settings['primary_links']) {
$settings['primary_links'] = theme('links', link_page());
}
}
else {
$settings['primary_links'] = '';
}
if (!$settings['toggle_secondary_links']) {
$settings['secondary_links'] = '';
}
}
return isset($settings[$setting_name]) ? $settings[$setting_name] : NULL;
}
/**
* @defgroup themeable Themeable functions
* @{
......@@ -476,6 +655,22 @@ function theme_mark() {
return '<span class="marker">*</span>';
}
/**
* Import a stylesheet using @import.
*
* @param $stylesheet
* The filename to point the link at.
*
* @param $media
* The media type to specify for the stylesheet
*
* @return
* A string containing the HTML for the stylesheet import.
*/
function theme_stylesheet_import($stylesheet, $media = 'all') {
return '<style type="text/css" media="'. $media .'">@import "'. $stylesheet .'";</style>';
}
/**
* Return a themed list of items.
*
......
......@@ -379,6 +379,11 @@ tr.light .form-item, tr.dark .form-item {
.node-form .poll-form fieldset {
display: block;
}
img.screenshot {
border: 1px solid #808080;
display: block;
margin: 2px;
}
#tracker td.replies {
text-align: center;
}
......
This diff is collapsed.
This diff is collapsed.
/* $Id$ */
/*
** HTML elements
*/
body {
margin: 0;
padding: 0;
color: #000;
background-color: #fff;
font: 76% Verdana, Arial, Helvetica, sans-serif;
}
tr.dark td, tr.light td {
padding: 0.3em;
}
h1, h2, h3, h4, h5, h6 {
margin: 0.5;
}
h1 {
font-size: 1.3em;
}
h2 {
font-size: 1.2em;
}
h3, h4, h5, h6 {
font-size: 1.1em;
}
a {
text-decoration: none;
font-weight: bold;
}
a:link {
color: #39c;
}
a:visited {
color: #369;
}
a:hover {
color: #39c;
text-decoration: underline;
}
fieldset {
border: 1px solid #ccc;
}
pre {
background-color: #eee;
padding: 0.75em 1.5em;
font-size: 12px;
border: 1px solid #ddd;
}
table {
/* make <td> sizes relative to body size! */
font-size: 1em;
}
.form-item label {
font-size: 1em;
color: #222;
}
.item-list .title {
font-size: 1em;
color: #222;
}
.links {
margin-bottom: 0em;
}
.comment .links {
margin-bottom: 0em;
}
/*
** Page layout blocks / IDs
*/
#header, #content {
width: 100%;
}
#header {
background-color: #69c;
}
#logo {
vertical-align: bottom;
border: 0;
font-weight: bold;
font-size: 1.9em;
color: #fff;
}
#logo img {
display: block;
}
#menu {
padding: 0.5em 0.5em 0 0.5em;
text-align: right;
vertical-align: middle;
}
#primary {
font-size: 1.0em;
padding: 0em 0.8em 0.5em 0;
color: #9cf;
}
#primary a {
font-weight: bold;
color: #fff;
}
#secondary {
padding: 0 1em 0.5em 0;
font-size: 0.8em;
color: #9cf;
}
#secondary a {
font-weight: bold;
color: #9cf;
}
#search .form-text, #search .form-submit {
border: 1px solid #369;
font-size: 1.1em;
}
#search .form-text {
width: 8em;
height: 1.4em;
padding: 0 0.5em 0 0.5em;
margin: 0 0 0.5em 0;
}
#search .form-submit {
height: 1.5em;
}
#mission {
background-color: #369;
padding: 1.5em 2em;
color: #fff;
}
#mission a, #mission a:visited {
color: #9cf;
font-weight: bold;
}
#main {
/* padding in px not ex because IE messes up 100% width tables otherwise */
padding: 10px;
}
#mission, .node .content, .comment .content {
line-height: 1.4;
}
#help {
font-size: 0.9em;
margin-bottom: 1em;
}
.breadcrumb {
margin-bottom: .5em;
}
.messages {
background-color: #eee;
border: 1px solid #ccc;
padding: 0.3em;
margin-bottom: 1em;
}
.error {
border-color: red;
}
#sidebar-left, #sidebar-right {
background-color: #ddd;
width: 16em;
/* padding in px not ex because IE messes up 100% width tables otherwise */
padding: 10px;
vertical-align: top;
}
#footer {
background-color: #eee;
padding: 1em;
font-size: 0.8em;
}
/*
** Common declarations for child classes of node, comment, block, box, etc.
** If you want any of them styled differently for a specific parent, add
** additional rules /with only the differing properties!/ to .parent .class.
** See .comment .title for an example.
*/
.title, .title a {
font-weight: bold;
font-size: 1.3em;
color: #777;
margin: 0 auto 0 auto; /* decrease default margins for h<x>.title */
}
.submitted {
color: #999;
font-size: 0.8em;
}
.links {
color: #999;
}
.links a {
font-weight: bold;
}
.block, .box {
padding: 0 0 1.5em 0;
}
.block {
border-bottom: 1px solid #bbb;
padding-bottom: 0.75em;
margin-bottom: 1.5em;
}
.block .title {
margin-bottom: .25em;
}
.box .title {
font-size: 1.1em;
}
.node {
margin: .5em 0 2em 0;
}
.sticky {
padding: .5em;
background-color: #eee;
border: solid 1px #ddd;
}
.node .content, .comment .content {
margin: .5em 0 .5em 0;
}
.node .taxonomy {
color: #999;
font-size: 0.8em;
padding: 1.5em;
}
.node .picture {
border: 1px solid #ddd;
float: right;
margin: 0.5em;
}
.comment {
border: 1px solid #abc;
padding: .5em;
margin-bottom: 1em;
}
.comment .title a {
font-size: 1.1em;
font-weight: normal;
}
.comment .new {
</