I'm using the latest Drupal 7.0 (January 5, 2011). The new CSS rule is not added, unnecessarily path on the resulting page is not correct.
Example:
Addeed: http://dl.dropbox.com/u/15840231/1.jpg
Incorrect path:
<style type="text/css" media="all">@import url("http://localhost/drupal7/sites%5Cdefault%5Cfiles%5Ccss_injector%5Ccss_injector_2.css?lfsxhg");</style>

<!--//--><![CDATA[//><!--
jQuery.extend(Drupal.settings, {"basePath":"\/drupal7\/","ajaxPageState":{"theme":"corolla","theme_token":"PHsZ26M8W_RQ2S6LiynCnb5OG3Ty4tr-i_VxsGbT_wY","js":{"misc\/jquery.js":1,"misc\/jquery.once.js":1,"misc\/drupal.js":1,"misc\/ui\/jquery.ui.core.min.js":1,"misc\/jquery.ba-bbq.js":1,"modules\/overlay\/overlay-parent.js":1,"modules\/contextual\/contextual.js":1,"misc\/jquery.cookie.js":1,"public:\/\/languages\/ru_lhv-lT85NFzK5S8rzoq9s5uttLBrc1JcECVUpbJO7Yg.js":1,"modules\/dhtml_menu\/dhtml_menu.js":1,"modules\/toolbar\/toolbar.js":1},"css":{"modules\/system\/system.base.css":1,"modules\/system\/system.menus.css":1,"modules\/system\/system.messages.css":1,"modules\/system\/system.theme.css":1,"misc\/ui\/jquery.ui.core.css":1,"misc\/ui\/jquery.ui.theme.css":1,"modules\/overlay\/overlay-parent.css":1,"modules\/contextual\/contextual.css":1,"modules\/comment\/comment.css":1,"modules\/field\/theme\/field.css":1,"modules\/node\/node.css":1,"modules\/poll\/poll.css":1,"modules\/search\/search.css":1,"modules\/user\/user.css":1,"modules\/dhtml_menu\/dhtml_menu.css":1,"themes\/corolla\/reset.css":1,"0":1,"modules\/toolbar\/toolbar.css":1,"modules\/shortcut\/shortcut.css":1,"themes\/corolla\/base.css":1,"themes\/corolla\/style.css":1,"themes\/corolla\/colors.css":1,"themes\/corolla\/print.css":1,"themes\/corolla\/ie8.css":1,"themes\/corolla\/ie7.css":1,"sites\\default\\files\\css_injector\\css_injector_2.css":1}},"dhtmlMenu":{"nav":"open","animation":{"effects":{"height":"height","opacity":"opacity"},"speed":500},"effects":{"siblings":"close-same-tree","children":"none","remember":0},"filter":{"type":"blacklist","list":[]}},"overlay":{"paths":{"admin":"node\/*\/edit\nnode\/*\/delete\nnode\/*\/revisions\nnode\/*\/revisions\/*\/revert\nnode\/*\/revisions\/*\/delete\nnode\/add\nnode\/add\/*\noverlay\/dismiss-message\nuser\/*\/shortcuts\nadmin\nadmin\/*\nbatch\ntaxonomy\/term\/*\/edit\nuser\/*\/cancel\nuser\/*\/edit\nuser\/*\/edit\/*","non_admin":"admin\/structure\/block\/demo\/*\nadmin\/reports\/status\/php"},"ajaxCallback":"overlay-ajax"},"tableHeaderOffset":"Drupal.toolbar.height"});
//--><!]]>

My user page: http://dl.dropbox.com/u/15840231/user.htm

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

rfay’s picture

The most recent dev release of CSS Injector is dated December 25.

I can't demonstrate any problems. Just created a rule

.content { color: red; }

and it works fine.

Perhaps you can go through step by step, explaining what you were trying to do and provide the rule that failed for you.

fir1st’s picture

And why may be incorrect path?

juggler’s picture

I have the same issue.

The url of the css file seems to be wrong:
http://localhost/drupal7/sites%5Cdefault%5Cfiles%5Ccss_injector%5Ccss_in...

It uses %5c (code for \) instead of /.
Im running this test-site on windows 7, maybe that's why its using backslash instead of slash.

If I go to: admin/config/development/css_injector
the filepath of my defined rule is:
sites\default\files\css_injector\css_injector_1.css

it's with backslash instead of slash. Maybe this info helps.

How can I fix it?
Thanks

juggler’s picture

Title: Incorrect path to css file on Windows » Incorrect path

It seems that the function call
drupal_realpath(_css_injector_rule_uri($crid));
returns a path with backslashes in windows.

If I add this line of code to the function "function _css_injector_rule_path($crid)":
$local_path = str_replace('\\', '/', $local_path);

everything works fine

rfay’s picture

Title: Incorrect path » Incorrect path to css file on Windows

drupal_realpath shouldn't be used for generating the URL, so that's the bug here. This should be using file_create_url($uri) instead.

drubeedoo’s picture

Title: Incorrect path » Incorrect path to css file on Windows

Still an issue... using XAMPP in Windows with Drupal 7.4 and latest version of css_injector-7.x-1.5.

CSS file is not loading due to CSS Injector output containing "%5C" instead of "/" in path. See path to file as generated by module:

http://localhost/dev/sites%5Cdefault%5Cfiles%5Ccss_injector%5Ccss_injector_1.css?lo3dn3

Thanks for looking into this...

rfay’s picture

#5 explains the fix if somebody wants to roll a patch.

rfay’s picture

#5 explains the fix if somebody wants to roll a patch.

gapple’s picture

Tried to get started on this, but file_create_url($uri) returns an absolute path.

The following works if you can assume that the public:// stream wrapper uses the same domain and base path as the drupal root.

function _css_injector_rule_path($crid) {
  if (!empty($crid)) {
    $local_path = file_create_url(_css_injector_rule_uri($crid));
    // Now remove the part before the drupal root.
    $local_path = substr_replace($local_path, '', 0, strlen(url('<front>', array('absolute' => TRUE))));
    return $local_path;
  }
  return NULL;
}

There has to be a better way to get a relative path from the stream wrapper if possible though, and some logic may be required to add the CSS to the page as an external path if a relative path is not possible (e.g. it's stored on a CDN)

bwill’s picture

This is an issue for me as well. My path is /sites%5Cdefault%5Cfiles%5Ccss_injector%5Ccss_injector_1.css?logl8a");
which does not work. My CSS code is:

.submitted {
display: none;
}
gapple’s picture

Here is another option, based on a patch to Insert module (#622964-51: Provide UI option for using relative urls for the inserted images).

It looks to be smarter in checking if the absolute path to the file matches the site's url and base path.

  $url = file_create_url(_css_injector_rule_uri($crid));
 
  global $base_root;
  // Convert to a relative URL if the file's absolute URL starts with $base_root.
  if (drupal_substr($url, 0, drupal_strlen($base_root)) == $base_root) {
    return drupal_substr($url, drupal_strlen($base_root));
  }

  return $url;
rfay’s picture

Status: Active » Needs review
FileSize
3.91 KB

This patch simplifies the code and I think is the correct approach.

Please review it and test on all platforms. It affects the admin display, deletion of rules, and adding rules in addition to loading the CSS, so there are a few things that can break.

That said, it works for me on both linux and Windows (under xampp)

gapple’s picture

Status: Needs review » Needs work
+++ b/css_injector.install
@@ -61,8 +61,8 @@ function css_injector_schema() {
-  foreach($rules as $id => $rule) {
-    file_unmanaged_delete(_css_injector_rule_path($id));
+  foreach($rules as $crid => $rule) {
+    file_unmanaged_delete(_css_injector_rule_uri($id));
   }

only one $id has been changed to $crid here.

Other than that, things look good and work properly on my Win environment. Digging through Drupal's CSS code it looks like since it uses file_create_url itself to ouput links when aggregation is disabled, it can handle paths to shipped files and stream wrappers even though the documentation for drupal_add_css only mentions shipped files.

bwill’s picture

The patch worked for me - running on Windows 7 in IE8. Thanks a bunch! This is a most excellent module! I even used it to display a background image behind my contact form!

rfay’s picture

Title: Incorrect path to css file on Windows » Fix file handling resulting in Incorrect path to css file on Windows
Status: Needs work » Fixed

Thanks, @gapple, for the careful review.

Since I seem to be the only committer hanging around here I've committed this with your change :=)

Committed: aea7119

We need to get out a new release, so if you all could test the dev and report back, that would be great.

Thanks to all for the work and the patience on this one. It actually resolves a number of other reported issues.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.