#141725 by Crell and dvessel: allow themes to define multiple CSS and JS files in their .info files, which can be clearly overriden

6.x
Gábor Hojtsy 2007-07-01 23:27:32 +00:00
parent 3409019929
commit 5e5a07f513
6 changed files with 62 additions and 39 deletions

View File

@ -100,33 +100,18 @@ function _init_theme($theme, $base_theme = array()) {
$theme_path = dirname($theme->filename);
// Add the default stylesheet
if (!empty($theme->stylesheet)) {
drupal_add_css($theme->stylesheet, 'theme');
}
else {
// If we don't have a stylesheet of our own, look for the first
// base to have one and use its.
foreach ($base_theme as $base) {
if (!empty($base->stylesheet)) {
drupal_add_css($base->stylesheet, 'theme');
break;
// Add stylesheets used by this theme.
if (!empty($theme->stylesheets)) {
foreach ($theme->stylesheets as $media => $stylesheets) {
foreach ($stylesheets as $stylesheet) {
drupal_add_css($stylesheet, 'theme', $media);
}
}
}
// Add the default script
if (!empty($theme->script)) {
drupal_add_js($theme->script, 'theme');
}
else {
// If we don't have a script of our own, look for the first
// base to have one and use its.
foreach ($base_theme as $base) {
if (!empty($base->script)) {
drupal_add_js($base->script, 'theme');
break;
}
// Add scripts used by this theme.
if (!empty($theme->scripts)) {
foreach ($theme->scripts as $script) {
drupal_add_js($script, 'theme');
}
}
@ -356,11 +341,17 @@ function list_themes($refresh = FALSE) {
while ($theme = db_fetch_object($result)) {
if (file_exists($theme->filename)) {
$theme->info = unserialize($theme->info);
if (!empty($theme->info['stylesheet']) && file_exists($theme->info['stylesheet'])) {
$theme->stylesheet = $theme->info['stylesheet'];
foreach ($theme->info['stylesheets'] as $media => $stylesheets) {
foreach ($stylesheets as $stylesheet => $path) {
if (file_exists($path)) {
$theme->stylesheets[$media][$stylesheet] = $path;
}
}
}
if (!empty($theme->info['script']) && file_exists($theme->info['script'])) {
$theme->script = $theme->info['script'];
foreach ($theme->info['scripts'] as $script => $path) {
if (file_exists($path)) {
$theme->scripts[$script] = $path;
}
}
if (isset($theme->info['engine'])) {
$theme->engine = $theme->info['engine'];

View File

@ -1047,8 +1047,10 @@ function system_theme_default() {
'search',
'slogan'
),
'stylesheet' => 'style.css',
'script' => 'script.js',
'stylesheets' => array(
'all' => array('style.css')
),
'scripts' => array('script.js'),
'screenshot' => 'screenshot.png',
'php' => DRUPAL_MINIMUM_PHP,
);
@ -1104,14 +1106,21 @@ function system_theme_data() {
}
}
// Give the stylesheet proper path information.
if (!empty($themes[$key]->info['stylesheet'])) {
$themes[$key]->info['stylesheet'] = dirname($themes[$key]->filename) .'/'. $themes[$key]->info['stylesheet'];
// Give the stylesheets proper path information.
$pathed_stylesheets = array();
foreach ($themes[$key]->info['stylesheets'] as $media => $stylesheets) {
foreach ($stylesheets as $stylesheet) {
$pathed_stylesheets[$media][$stylesheet] = dirname($themes[$key]->filename) .'/'. $stylesheet;
}
}
// Give the script proper path information.
if (!empty($themes[$key]->info['script'])) {
$themes[$key]->info['script'] = dirname($themes[$key]->filename) .'/'. $themes[$key]->info['script'];
$themes[$key]->info['stylesheets'] = $pathed_stylesheets;
// Give the scripts proper path information.
$scripts = array();
foreach ($themes[$key]->info['scripts'] as $script) {
$scripts[$script] = dirname($themes[$key]->filename) .'/'. $script;
}
$themes[$key]->info['scripts'] = $scripts;
// Give the screenshot proper path information.
if (!empty($themes[$key]->info['screenshot'])) {
$themes[$key]->info['screenshot'] = dirname($themes[$key]->filename) .'/'. $themes[$key]->info['screenshot'];
@ -1137,6 +1146,28 @@ function system_theme_data() {
$themes[$key]->prefix = $key;
}
}
// Add any stylesheets from the base theme, unless the names match in which case
// the sub-theme wins. Note that we slip the base theme's stylesheets in at the
// beginning of the array so that they get added to the page in the correct order.
foreach ($themes[$base_key]->info['stylesheets'] as $media => $stylesheets) {
foreach ($stylesheets as $stylesheet => $path) {
if (!isset($themes[$key]->info['stylesheets'][$media][$stylesheet])) {
// We need to ensure the media array exists, or the array addition below doesn't work.
if (!isset($themes[$key]->info['stylesheets'][$media])) {
$themes[$key]->info['stylesheets'][$media] = array();
}
$themes[$key]->info['stylesheets'][$media] = array($stylesheet => $path) + $themes[$key]->info['stylesheets'][$media];
}
}
}
// Add any scripts from the base theme, unless the names match in which case
// the sub-theme wins. Note that we slip the base theme's scripts in at the
// beginning of the array so that they get added to the page in the correct order.
foreach ($themes[$base_key]->info['scripts'] as $script => $path) {
if (!isset($themes[$key]->info['scripts'][$script])) {
$themes[$key]->info['scripts'] = array($script => $path) + $themes[$key]->info['scripts'];
}
}
}
// Extract current files from database.

View File

@ -7,5 +7,7 @@ features[] = logo
features[] = favicon
features[] = name
features[] = slogan
stylesheets[all][] = style.css
stylesheets[all][] = common.css
version = VERSION
core = 6.x

View File

@ -29,8 +29,6 @@ function chameleon_page($content, $show_blocks = TRUE, $show_messages = TRUE) {
drupal_set_html_head('<link rel="shortcut icon" href="'. check_url(theme_get_setting('favicon')) .'" type="image/x-icon" />');
}
drupal_add_css(path_to_theme() .'/common.css', 'theme');
$title = drupal_get_title();
// Get blocks before so that they can alter the header (JavaScript, Stylesheets etc.)

View File

@ -4,3 +4,5 @@ description = Tableless, recolorable, multi-column, fluid width theme (default).
version = VERSION
core = 6.x
engine = phptemplate
stylesheets[all][] = style.css
stylesheets[print][] = print.css

View File

@ -6,7 +6,6 @@
<?php print $head ?>
<?php print $styles ?>
<?php print $scripts ?>
<style type="text/css" media="print">@import "<?php print base_path() . path_to_theme() ?>/print.css";</style>
<!--[if lt IE 7]>
<style type="text/css" media="all">@import "<?php print base_path() . path_to_theme() ?>/fix-ie.css";</style>
<![endif]-->