Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
project
drupal
Commits
2c0571b8
Commit
2c0571b8
authored
Aug 03, 2006
by
Dries Buytaert
Browse files
- Patch
#73961
by m3avrck, timcn, et al: simplify adding CSS in Drupal.
parent
010eca98
Changes
7
Hide whitespace changes
Inline
Side-by-side
includes/bootstrap.inc
View file @
2c0571b8
...
...
@@ -194,7 +194,7 @@ function conf_init() {
* than by consulting the database.
* @param $check_db
* Allows the database search to be skipped (useful for pre-bootstrap
* checks where configuration paths must still be respected).
* checks where configuration paths must still be respected).
*
* @return
* The filename of the requested item.
...
...
includes/common.inc
View file @
2c0571b8
...
...
@@ -115,7 +115,7 @@ function drupal_set_html_head($data = NULL) {
*/
function
drupal_get_html_head
()
{
$output
=
"<meta http-equiv=
\"
Content-Type
\"
content=
\"
text/html; charset=utf-8
\"
/>
\n
"
;
$output
.
=
theme
(
'stylesheet_import'
,
base_path
()
.
'misc/drupal.css'
);
drupal_add_css
(
'misc/drupal.css'
,
'core'
);
return
$output
.
drupal_set_html_head
();
}
...
...
@@ -1203,6 +1203,53 @@ function drupal_add_link($attributes) {
drupal_set_html_head
(
'<link'
.
drupal_attributes
(
$attributes
)
.
" />
\n
"
);
}
/**
* Adds a CSS file to the stylesheet queue.
*
* @param $path
* The path to the CSS file relative to the base_path(), e.g., /modules/devel/devel.css.
* @param $type
* The type of stylesheet that is being added. Types are: core, module, and theme.
* @param $media
* (optional) The media type for the stylesheet, e.g., all, print, screen.
* @return
* An array of CSS files.
*/
function
drupal_add_css
(
$path
=
NULL
,
$type
=
'module'
,
$media
=
'all'
)
{
static
$css
=
array
(
'core'
=>
array
(),
'module'
=>
array
(),
'theme'
=>
array
());
if
(
!
is_null
(
$path
))
{
$css
[
$type
][
$path
]
=
array
(
'path'
=>
$path
,
'media'
=>
$media
);
}
return
$css
;
}
/**
* Returns a themed representation of all stylesheets that should be attached to the page.
* It loads the CSS in order, with 'core' CSS first, then 'module' CSS, then 'theme' CSS files.
* This ensures proper cascading of styles for easy overriding in modules and themes.
*
* @param $css
* (optional) An array of CSS files. If no array is provided, the default stylesheets array is used instead.
* @return
* A string of XHTML CSS tags.
*/
function
drupal_get_css
(
$css
=
NULL
)
{
$output
=
''
;
if
(
is_null
(
$css
))
{
$css
=
drupal_add_css
();
}
foreach
(
$css
as
$type
)
{
foreach
(
$type
as
$file
)
{
$output
.
=
'<style type="text/css" media="'
.
$file
[
'media'
]
.
'">@import "'
.
base_path
()
.
$file
[
'path'
]
.
"
\"
;</style>
\n
"
;
}
}
return
$output
;
}
/**
* Add a JavaScript file to the output.
*
...
...
includes/install.inc
View file @
2c0571b8
...
...
@@ -270,7 +270,7 @@ function drupal_verify_profile($profile) {
// Get a list of modules required by this profile.
$function
=
$profile
.
'_profile_modules'
;
$module_list
=
array_merge
(
array
(
'system'
),
$function
());
// Verify that all required modules exist.
$modules_present
=
TRUE
;
foreach
(
$module_list
as
$module
)
{
...
...
@@ -311,7 +311,7 @@ function drupal_install_profile($profile, $module_list) {
// Install schemas for profile and all its modules.
module_rebuild_cache
();
drupal_install_modules
(
$module_list
);
// And now, run the profile's install function.
$function
=
$profile
.
'_install'
;
if
(
function_exists
(
$function
))
{
...
...
includes/module.inc
View file @
2c0571b8
...
...
@@ -89,7 +89,7 @@ function module_list($refresh = FALSE, $bootstrap = TRUE, $sort = FALSE, $fixed_
/**
* Rebuild the database cache of module files.
*
*
* @return
* The array of filesystem objects used to rebuild the cache.
*/
...
...
includes/theme.inc
View file @
2c0571b8
...
...
@@ -53,19 +53,19 @@ function init_theme() {
// If we're using a style, load its appropriate theme,
// which is stored in the style's description field.
// Also
lo
ad the stylesheet using
theme_add_style
().
// Also a
d
d the stylesheet using
drupal_add_css
().
// Otherwise, load the theme.
if
(
strpos
(
$themes
[
$theme
]
->
filename
,
'.css'
))
{
// File is a style; loads its CSS.
// Set theme to its template/theme
theme_add_style
(
$themes
[
$theme
]
->
filename
);
drupal_add_css
(
$themes
[
$theme
]
->
filename
,
'theme'
);
$theme
=
basename
(
dirname
(
$themes
[
$theme
]
->
description
));
}
else
{
// File is a template/theme
// Load its CSS, if it exists
if
(
file_exists
(
$stylesheet
=
dirname
(
$themes
[
$theme
]
->
filename
)
.
'/style.css'
))
{
theme_add_style
(
$stylesheet
);
drupal_add_css
(
$stylesheet
,
'theme'
);
}
}
...
...
@@ -324,33 +324,6 @@ function theme_get_setting($setting_name, $refresh = FALSE) {
return
isset
(
$settings
[
$setting_name
])
?
$settings
[
$setting_name
]
:
NULL
;
}
/**
* Add a theme stylesheet to be included later. This is handled separately from
* drupal_set_html_head() to enforce the correct CSS cascading order.
*/
function
theme_add_style
(
$path
=
''
,
$media
=
'all'
)
{
static
$styles
=
array
();
if
(
$path
&&
!
isset
(
$styles
[
"
$media
:
$path
"
]))
{
$style
=
new
stdClass
();
$style
->
path
=
base_path
()
.
$path
;
$style
->
media
=
$media
;
$styles
[
"
$media
:
$path
"
]
=
$style
;
}
return
$styles
;
}
/**
* Return the HTML for a theme's stylesheets.
*/
function
theme_get_styles
()
{
$output
=
''
;
foreach
(
theme_add_style
()
as
$style
)
{
$output
.
=
theme
(
'stylesheet_import'
,
$style
->
path
,
$style
->
media
);
}
return
$output
;
}
/**
* @defgroup themeable Themeable functions
* @{
...
...
@@ -392,7 +365,7 @@ function theme_page($content) {
$output
.
=
'<head>'
;
$output
.
=
' <title>'
.
(
drupal_get_title
()
?
strip_tags
(
drupal_get_title
())
:
variable_get
(
'site_name'
,
'drupal'
))
.
'</title>'
;
$output
.
=
drupal_get_html_head
();
$output
.
=
theme_get_style
s
();
$output
.
=
drupal_get_cs
s
();
$output
.
=
' </head>'
;
$output
.
=
' <body style="background-color: #fff; color: #000;">'
;
...
...
@@ -433,7 +406,7 @@ function theme_maintenance_page($content, $messages = TRUE, $partial = FALSE) {
$output
.
=
'<head>'
;
$output
.
=
' <title>'
.
strip_tags
(
drupal_get_title
())
.
'</title>'
;
$output
.
=
drupal_get_html_head
();
$output
.
=
theme_get_style
s
();
$output
.
=
drupal_get_cs
s
();
$output
.
=
'</head>'
;
$output
.
=
'<body>'
;
$output
.
=
'<h1>'
.
drupal_get_title
()
.
'</h1>'
;
...
...
@@ -462,7 +435,7 @@ function theme_install_page($content) {
$output
.
=
'<head>'
;
$output
.
=
' <title>'
.
strip_tags
(
drupal_get_title
())
.
'</title>'
;
$output
.
=
drupal_get_html_head
();
$output
.
=
theme_get_style
s
();
$output
.
=
drupal_get_cs
s
();
$output
.
=
'</head>'
;
$output
.
=
'<body>'
;
$output
.
=
'<h1>'
.
drupal_get_title
()
.
'</h1>'
;
...
...
@@ -855,22 +828,6 @@ function theme_mark($type = MARK_NEW) {
}
}
/**
* Import a stylesheet using @import.
*
* @param $path
* The path to the stylesheet.
*
* @param $media
* The media type to specify for the stylesheet
*
* @return
* A string containing the HTML for the stylesheet import.
*/
function
theme_stylesheet_import
(
$path
,
$media
=
'all'
)
{
return
'<style type="text/css" media="'
.
$media
.
'">@import "'
.
$path
.
'";</style>'
;
}
/**
* Return a themed list of items.
*
...
...
themes/chameleon/chameleon.theme
View file @
2c0571b8
...
...
@@ -28,6 +28,8 @@ function chameleon_page($content) {
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();
$output = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n";
...
...
@@ -35,8 +37,7 @@ function chameleon_page($content) {
$output .= "<head>\n";
$output .= " <title>". ($title ? strip_tags($title) ." | ". variable_get("site_name", "drupal") : variable_get("site_name", "drupal") ." | ". variable_get("site_slogan", "")) ."</title>\n";
$output .= drupal_get_html_head();
$output .= theme('stylesheet_import', base_path() . path_to_theme() ."/common.css");
$output .= theme_get_styles();
$output .= drupal_get_css();
$output .= "</head>";
$output .= "<body>\n";
$output .= " <div id=\"header\">";
...
...
themes/engines/phptemplate/phptemplate.engine
View file @
2c0571b8
...
...
@@ -210,7 +210,8 @@ function phptemplate_page($content) {
'sidebar_right'
=>
$sidebar_right
,
'site_name'
=>
(
theme_get_setting
(
'toggle_name'
)
?
variable_get
(
'site_name'
,
'Drupal'
)
:
''
),
'site_slogan'
=>
(
theme_get_setting
(
'toggle_slogan'
)
?
variable_get
(
'site_slogan'
,
''
)
:
''
),
'styles'
=>
theme_get_styles
(),
'css'
=>
drupal_add_css
(),
'styles'
=>
drupal_get_css
(),
'tabs'
=>
theme
(
'menu_local_tasks'
),
'title'
=>
drupal_get_title
()
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment