Hi,

When we switched to private download method for serving files, the sky theme unexpectedly switched back to (default) fixed width instead of the fluid we had choses.

The problem is caused by a file path (c:/wamp/files/sky/custom.css) that is not properly rendered into the /drupal/system/sky/custom.css it should be for this download method.

The custom css is correctly created btw inside the c:/wamp/files/sky/ directory but not included in the final web pages correctly (it's included as http:///drupal/c:/wamp/files/sky/custom.css).

Comments

palazis’s picture

Hello,

Thanks for the excellent theme.

I can confirm that after changing the download method to private, the (default) fixed width is used instead of the chosen one.
Additionally, all the other settings (e.g. fonts, etc) are also ignored.
Most probably the cause is the one mentioned by wvd_vegt.
A fast fix is to embed each and every line of custom.css into style.css.
Of course, it would be much better if this could be fixed in a more "official" way, e.g. by providing a new release.

Thanks in advance

aimutch’s picture

My understanding of the private download method is that you are supposed to use relative paths, not absolute paths like C:\wamp\files\....

Try it again with a relative path and let us know if it's still not working.

jacine’s picture

Sorry for such a late response here, this is actually my first time seeing this issue :(

custom.css is a file that is generated according to what your choices are on the theme settings page. I think it's permissions issue caused by setting files to private. As far as I am aware, Drupal only has permission to generate files in the files directory, which is why it's not generated in the theme folder in the first place. There are limitations with Drupal that I am aware of when using Private downloads... For example:

  • You cannot optimize CSS or Javascript at admin/settings/performance
  • Even Garlands color options go away on the theme settings page

These methods require files to be created in the files directory, like the custom.css file in the Sky theme, so really it's not a bug with the theme, it's a limitation of Drupal as a result of settings downloads to private.

The only thing I can think of to make it work, is to print the generated CSS in the <head> tag, which I would rather not do, since it's a sloppy way of doing it. Of course embedding the code manually in style.css at the very bottom would work too, though that's not a great solution either.

Maybe someone has a better idea? If not, I'm going to mark this issue "Won't fix" though I really mean "Can't fix" ;)

wvd_vegt’s picture

Hi,

It's just the link generated that's not correct (so more a code problem). The css is generated correctly at the place where it should. It's however not included properly. Maybe it's an idea to use/geneate a php script that emits the css with proper mime type (see the following firefox observation below).

One thing though that gives problems (accoriding to my notes) is that firefox has problems with a wrong mimetype when the file is located at files/sky.

Here is my version of the code & comments (note it tests for generated version but uses a manual copy):


$custom_css gets a value of 'c:/wamp/files/sky/custom.css' which becomes something like
http:///drupal/c:/wamp/files/sky/custom.css when used in an hyperlink. And that is an invalid link causing it not to be doenloaded & included as it should.

// Theme Settings Generated CSS
//veg: Disabled because it does not include properly, moved code to _sky_conditional_stylesheets() below
//veg: Downloading from /files/sky gives a wrong mime type -> firefox problems.
//veg: Note we still check for the default location, but we need a copy in the themes css directory.
$custom_css = file_directory_path() .'/sky/custom.css';
if (file_exists($custom_css)) {
  drupal_add_css(path_to_theme() .'/css/custom.css', 'theme', 'all', TRUE);
//drupal_add_css($custom_css, 'theme', 'all', TRUE);
}
wvd_vegt’s picture

Hi,

I have got a solution for the problem.

1) In Template.php only use drupal_add_css for public downloads (drupal_add_css fails for private stylesheets).

//veg: 02-02-2009 - Default code only when Public Downloads.
$custom_css = file_directory_path() .'/sky/custom.css';
if (file_exists($custom_css)) {
  if (variable_get('file_downloads', NULL) == FILE_DOWNLOADS_PUBLIC) {
		drupal_add_css($custom_css, 'theme', 'all', TRUE);
  }
}

2) Extend the function _sky_conditional_stylesheets() a bit so it adds the stylesheet after the conditional ones if the download method is private:

// Conditional stylesheets for IE
function _sky_conditional_stylesheets() {
  $output = "\n".'<!--[if IE 6.0]><link rel="stylesheet" href="'. base_path() . path_to_theme() .'/css/ie-6.css" type="text/css" media="all" charset="utf-8" /><![endif]-->'."\n";
  $output .= '<!--[if IE 7.0]><link rel="stylesheet" href="'. base_path() . path_to_theme() .'/css/ie-7.css" type="text/css" media="all" charset="utf-8" /><![endif]-->'."\n";

//veg: 02-02-2009 - hardcoded link when Private Downloads.
//                  NOTE: it needs the sky module to fix the mimetype for FireFox 
//								        when downloading from base_path()./system/files/sky/custom.css. 
//	                      Drupal sends a mime-type application/x-download which FireFox ignores.

	$custom_css = file_directory_path() .'/sky/custom.css';
	if (file_exists($custom_css)) {
		if (variable_get('file_downloads', NULL) == FILE_DOWNLOADS_PRIVATE) {
			$custom_css = base_path() .'system/files/sky/custom.css';
			//outputdebugstring($custom_css,"sky (private)");
			$output .= "\n".'<link type="text/css" rel="stylesheet" media="all" href="'.$custom_css.'" />'."\n";
		}
	}
	
  return $output;
}

3) Now the funny part. When drupal serves a file from base_path().'/system/files' it always seems to use a mimetype of 'application/x-download' unless a module overrides it in a hook_file_download().

This is where FireFox stumbles (IE and others just homour the mime type supllied in the html, FireFox looks to the actual download too and then just refuses it).

Baseline I wrote a very small sky module that supplies the correct mime type when downloading the custom.css file if the download methods is set to private.

Sky.info:

; $Id: sky.info,v 1.5 2008/10/03 03:44:07 wvd_vegt Exp $
name = Sky
description = Sky theme helper.
core = 6.x

; Information added by drupal.org packaging script on 2007-09-29
version = "6.x"
project = "sky"
datestamp = "1193629803"

Sky.install:

<?php

// $Id: sky.install,v 1.5 2008/10/03 03:44:07 wvd_vegt Exp $

/**
 * @file
 * Sky theme helper.
 */
function sky_select_types_install() {  
}

sky.module:

<?php

// $Id: sky.module, v 1.5 2008/10/03 03:44:07 wvd_vegt Exp $

/**
 * @file
 * Sky theme helper.
 *
 * Fixes the mimetype for custom.css if the download method is set to private. 
 * Only FireFox seems to be affected (and refuses to download with the default.
 * application/x-download that Drupal supplies.
 *
 * veg:02-02-2009 - Created.
 */

/**
 * Implementation of hook_file_download(). 
 */
function sky_file_download($filepath) {
  if ($filepath=="sky/custom.css" && 
      variable_get('file_downloads', NULL) == FILE_DOWNLOADS_PRIVATE) {
    return 'Content-Type: text/css; authoritative=true';
  }
}

So basically for sites with a public download method nothing changes. For private download the location of the custom.css include changes a bit and for FireFox a small module needs to be installed and activated.

As far as i can see the only thing not 100% correct is that if the cache is cleared, the custom.css is not forces to be re-downloaded (by appending random query suffix).

jacine’s picture

Very interesting...

I'm not 100% sold on adding a module to maintain in order to use the theme, just because of private downloads because I don't believe a contrib theme should contain a module to work properly:

However, IMHO, if this is considered an acceptable solution it would most likely be more useful as an optional standalone module or even core patch because:

  • Other contrib themes (and possibly modules) that are interested in taking full advantage of the theme settings in this way can do so
  • It would only be necessary to download if you use private downloads
  • And hopefully with some more "developer" eyes on it, the caching issues could be solved as well
aimutch’s picture

I agree that this should be a problem addressed in the Drupal core code. If Drupal enables this kind of feature, the problem should be fixed there, not at the theme level.

wvd_vegt’s picture

Hi,

Off-course I do agree with both previous posts, I just added the module for those wanting a fix now (even though it's clumsy and should be fixed in the Drupal core).

We use the module with some FireFox users (including our boss) with private upload method and variable width (so a very special case).

So it should not be considered a patch but merely a want to get it working until it's properly fixed in the core (and only if you have this kind of setup). It took me a while to figure out whats causing it and documenting it in a fix is perhaps the best way.

Btw for those using it, you should change the name as a module and a theme with the same name is someting Drupal doesn't like (I know named it sky_fix).

Maybe promoting it as a separate module isn't a bad idea so you can fix certain mime types causing problems.

jacine’s picture

Status: Active » Closed (fixed)