comparison includes/common.inc @ 3:165d43f946a8 6.1

Drupal 6.1
author Franck Deroche <webmaster@defr.org>
date Tue, 23 Dec 2008 14:29:21 +0100
parents c1f4ac30525a
children 2427550111ae
comparison
equal deleted inserted replaced
2:85b5b336180c 3:165d43f946a8
1 <?php 1 <?php
2 // $Id: common.inc,v 1.756.2.4 2008/02/13 14:25:42 goba Exp $ 2 // $Id: common.inc,v 1.756.2.7 2008/02/27 19:44:44 goba Exp $
3 3
4 /** 4 /**
5 * @file 5 * @file
6 * Common functions that many Drupal modules will need to reference. 6 * Common functions that many Drupal modules will need to reference.
7 * 7 *
1582 } 1582 }
1583 1583
1584 /** 1584 /**
1585 * Adds a CSS file to the stylesheet queue. 1585 * Adds a CSS file to the stylesheet queue.
1586 * 1586 *
1587 * Themes may replace module-defined CSS files by adding a stylesheet with the
1588 * same filename. For example, themes/garland/system-menus.css would replace
1589 * modules/system/system-menus.css. This allows themes to override complete
1590 * CSS files, rather than specific selectors, when necessary.
1591 *
1592 * @param $path 1587 * @param $path
1593 * (optional) The path to the CSS file relative to the base_path(), e.g., 1588 * (optional) The path to the CSS file relative to the base_path(), e.g.,
1594 * /modules/devel/devel.css. 1589 * /modules/devel/devel.css.
1595 * 1590 *
1596 * Modules should always prefix the names of their CSS files with the module 1591 * Modules should always prefix the names of their CSS files with the module
1597 * name, for example: system-menus.css rather than simply menus.css. Themes 1592 * name, for example: system-menus.css rather than simply menus.css. Themes
1598 * can override module-supplied CSS files based on their filenames, and this 1593 * can override module-supplied CSS files based on their filenames, and this
1599 * prefixing helps prevent confusing name collisions for theme developers. 1594 * prefixing helps prevent confusing name collisions for theme developers.
1595 * See drupal_get_css where the overrides are performed.
1600 * 1596 *
1601 * If the direction of the current language is right-to-left (Hebrew, 1597 * If the direction of the current language is right-to-left (Hebrew,
1602 * Arabic, etc.), the function will also look for an RTL CSS file and append 1598 * Arabic, etc.), the function will also look for an RTL CSS file and append
1603 * it to the list. The name of this file should have an '-rtl.css' suffix. 1599 * it to the list. The name of this file should have an '-rtl.css' suffix.
1604 * For example a CSS file called 'name.css' will have a 'name-rtl.css' 1600 * For example a CSS file called 'name.css' will have a 'name-rtl.css'
1605 * file added to the list, if exists in the same directory. This CSS file 1601 * file added to the list, if exists in the same directory. This CSS file
1606 * should contain overrides for properties which should be reversed or 1602 * should contain overrides for properties which should be reversed or
1607 * otherwise different in a right-to-left display. 1603 * otherwise different in a right-to-left display.
1608 *
1609 * If the original CSS file is being overridden by a theme, the theme is
1610 * responsible for supplying an accompanying RTL CSS file to replace the
1611 * module's.
1612 * @param $type 1604 * @param $type
1613 * (optional) The type of stylesheet that is being added. Types are: module 1605 * (optional) The type of stylesheet that is being added. Types are: module
1614 * or theme. 1606 * or theme.
1615 * @param $media 1607 * @param $media
1616 * (optional) The media type for the stylesheet, e.g., all, print, screen. 1608 * (optional) The media type for the stylesheet, e.g., all, print, screen.
1649 if (isset($path)) { 1641 if (isset($path)) {
1650 // This check is necessary to ensure proper cascading of styles and is faster than an asort(). 1642 // This check is necessary to ensure proper cascading of styles and is faster than an asort().
1651 if (!isset($css[$media])) { 1643 if (!isset($css[$media])) {
1652 $css[$media] = array('module' => array(), 'theme' => array()); 1644 $css[$media] = array('module' => array(), 'theme' => array());
1653 } 1645 }
1654
1655 // If a theme is adding the current stylesheet, check for any existing CSS files
1656 // with the same name. If they exist, remove them and allow the theme's own CSS
1657 // file to replace it.
1658 if ($type == 'theme') {
1659 foreach ($css[$media]['module'] as $old_path => $old_preprocess) {
1660 // Match by style sheet name.
1661 if (basename($path) == basename($old_path)) {
1662 unset($css[$media]['module'][$old_path]);
1663
1664 // If the current language is RTL and the CSS file had an RTL variant,
1665 // pull out the original. The theme must provide its own RTL style.
1666 if (defined('LANGUAGE_RTL') && $language->direction == LANGUAGE_RTL) {
1667 $rtl_old_path = str_replace('.css', '-rtl.css', $old_path);
1668 if (isset($css[$media]['module'][$rtl_old_path])) {
1669 unset($css[$media]['module'][$rtl_old_path]);
1670 }
1671 }
1672 // Set the preprocess state of the current module, then exit the search loop.
1673 $preprocess = $old_preprocess;
1674 break;
1675 }
1676 }
1677 }
1678 $css[$media][$type][$path] = $preprocess; 1646 $css[$media][$type][$path] = $preprocess;
1679 1647
1680 // If the current language is RTL, add the CSS file with RTL overrides. 1648 // If the current language is RTL, add the CSS file with RTL overrides.
1681 if (defined('LANGUAGE_RTL') && $language->direction == LANGUAGE_RTL) { 1649 if (defined('LANGUAGE_RTL') && $language->direction == LANGUAGE_RTL) {
1682 $rtl_path = str_replace('.css', '-rtl.css', $path); 1650 $rtl_path = str_replace('.css', '-rtl.css', $path);
1690 } 1658 }
1691 1659
1692 /** 1660 /**
1693 * Returns a themed representation of all stylesheets that should be attached to the page. 1661 * Returns a themed representation of all stylesheets that should be attached to the page.
1694 * 1662 *
1695 * It loads the CSS in order, with 'core' CSS first, then 'module' CSS, then 1663 * It loads the CSS in order, with 'module' first, then 'theme' afterwards.
1696 * 'theme' CSS files. This ensures proper cascading of styles for easy 1664 * This ensures proper cascading of styles so themes can easily override
1697 * overriding in modules and themes. 1665 * module styles through CSS selectors.
1666 *
1667 * Themes may replace module-defined CSS files by adding a stylesheet with the
1668 * same filename. For example, themes/garland/system-menus.css would replace
1669 * modules/system/system-menus.css. This allows themes to override complete
1670 * CSS files, rather than specific selectors, when necessary.
1671 *
1672 * If the original CSS file is being overridden by a theme, the theme is
1673 * responsible for supplying an accompanying RTL CSS file to replace the
1674 * module's.
1698 * 1675 *
1699 * @param $css 1676 * @param $css
1700 * (optional) An array of CSS files. If no array is provided, the default 1677 * (optional) An array of CSS files. If no array is provided, the default
1701 * stylesheets array is used instead. 1678 * stylesheets array is used instead.
1702 * @return 1679 * @return
1722 1699
1723 foreach ($css as $media => $types) { 1700 foreach ($css as $media => $types) {
1724 // If CSS preprocessing is off, we still need to output the styles. 1701 // If CSS preprocessing is off, we still need to output the styles.
1725 // Additionally, go through any remaining styles if CSS preprocessing is on and output the non-cached ones. 1702 // Additionally, go through any remaining styles if CSS preprocessing is on and output the non-cached ones.
1726 foreach ($types as $type => $files) { 1703 foreach ($types as $type => $files) {
1704 if ($type == 'module') {
1705 // Setup theme overrides for module styles.
1706 $theme_styles = array();
1707 foreach (array_keys($css[$media]['theme']) as $theme_style) {
1708 $theme_styles[] = basename($theme_style);
1709 }
1710 }
1727 foreach ($types[$type] as $file => $preprocess) { 1711 foreach ($types[$type] as $file => $preprocess) {
1712 // If the theme supplies its own style using the name of the module style, skip its inclusion.
1713 // This includes any RTL styles associated with its main LTR counterpart.
1714 if ($type == 'module' && in_array(str_replace('-rtl.css', '.css', basename($file)), $theme_styles)) {
1715 continue;
1716 }
1728 if (!$preprocess || !($is_writable && $preprocess_css)) { 1717 if (!$preprocess || !($is_writable && $preprocess_css)) {
1729 // If a CSS file is not to be preprocessed and it's a module CSS file, it needs to *always* appear at the *top*, 1718 // If a CSS file is not to be preprocessed and it's a module CSS file, it needs to *always* appear at the *top*,
1730 // regardless of whether preprocessing is on or off. 1719 // regardless of whether preprocessing is on or off.
1731 if (!$preprocess && $type == 'module') { 1720 if (!$preprocess && $type == 'module') {
1732 $no_module_preprocess .= '<link type="text/css" rel="stylesheet" media="'. $media .'" href="'. base_path() . $file . $query_string .'" />'."\n"; 1721 $no_module_preprocess .= '<link type="text/css" rel="stylesheet" media="'. $media .'" href="'. base_path() . $file . $query_string .'" />'."\n";