Allow external CSS files through drupal_add_css

From: Jonathan Hedstrom <jhedstrom@opensourcery.com>

http://drupal.org/node/264876
---

 includes/common.inc                  |   11 ++++++++++-
 modules/simpletest/tests/common.test |   20 ++++++++++++++++++++
 2 files changed, 30 insertions(+), 1 deletions(-)

diff --git includes/common.inc includes/common.inc
index fe0caf5..24ad919 100644
--- includes/common.inc
+++ includes/common.inc
@@ -2267,13 +2267,16 @@ function drupal_add_link($attributes) {
  *   - 'inline': A string of CSS that should be placed in the given scope. Note
  *     that it is better practice to use 'module' or 'theme' stylesheets, rather
  *     than 'inline' as the CSS would then be aggregated and cached.
+ *   - 'external': Inlcude an external CSS file that is not hosted on the local
+ *     server. These files will not be aggregated if CSS aggregation is
+ *     enabled.
  *
  * @param $options
  *   (optional) A string defining the 'type' of CSS that is being added in the
  *   $data parameter ('module', 'theme' or 'inline'), or an associative array of
  *   additional options, with the following keys:
  *   - 'type': The type of stylesheet that is being added. Types are: 'module',
- *     'theme' or 'inline'. Defaults to 'module'.
+ *     'theme', 'external' or 'inline'. Defaults to 'module'.
  *   - 'media': The media type for the stylesheet, e.g., all, print, screen.
  *     Defaults to 'all'.
  *   - 'preprocess': Allows the CSS to be aggregated and compressed if the
@@ -2410,6 +2413,12 @@ function drupal_get_css($css = NULL) {
         if ($type == 'inline') {
           $no_inline_preprocess .= drupal_load_stylesheet_content($data, $preprocess);
         }
+        // Include external stylesheets.
+        elseif ($type == 'external') {
+          $output .= '<link type="text/css" rel="stylesheet" media="' . $media . '" href="' . $data . $query_string . '" />' . "\n";
+          // Unset external file to prevent attempted inclusion when CSS aggregation is enabled.
+          unset($types[$type][$data]);
+        }
         // Only include the stylesheet if it exists.
         elseif (file_exists($data)) {
           if (!$preprocess || !($is_writable && $preprocess_css)) {
diff --git modules/simpletest/tests/common.test modules/simpletest/tests/common.test
index 2843137..f4a86f6 100644
--- modules/simpletest/tests/common.test
+++ modules/simpletest/tests/common.test
@@ -215,6 +215,17 @@ class CascadingStylesheetsTestCase extends DrupalWebTestCase {
   }
 
   /**
+   * Tests adding an external stylesheet.
+   */
+  function testAddExternal() {
+    $path = 'http://example.com/style.css';
+    $css = drupal_add_css($path, 'external');
+    $this->assertEqual($css['all']['external'][$path], TRUE, t('Adding an external CSS file caches it properly.'));
+
+    
+  }
+
+  /**
    * Makes sure that reseting the CSS empties the cache.
    */
   function testReset() {
@@ -232,6 +243,15 @@ class CascadingStylesheetsTestCase extends DrupalWebTestCase {
   }
 
   /**
+   * Tests rendering an external stylesheet.
+   */
+  function testRenderExternal() {
+    $css = 'http://example.com/style.css';
+    drupal_add_css($css, 'external');
+    $this->assertTrue(strpos(drupal_get_css(), 'href="' . $css) > 0, t('Rendering an external CSS file.'));
+  }
+
+  /**
    * Tests rendering inline stylesheets with preprocessing on.
    */
   function testRenderInlinePreprocess() {
