Warning: file_get_contents(): Filename cannot be empty in _locale_parse_js_file() includes/locale.inc)
backtrace:
file_get_contents('') locale.inc:1502
_locale_parse_js_file('https://maps.googleapis.com/maps/api/js?sensor=true') locale.module:917
locale_js_alter(Array, NULL, NULL, NULL) module.inc:1109
drupal_alter('js', Array) common.inc:4271
drupal_get_js('footer') theme.inc:2631
template_process_html(Array, 'html') theme.inc:1122
theme('html', Array) common.inc:5930
drupal_render(Array) common.inc:5777
Looking at the code I am not sure what is done with external js files like this.
the locale.inc file is:
function _locale_parse_js_file($filepath) {
global $language;
// The file path might contain a query string, so make sure we only use the
// actual file.
$parsed_url = drupal_parse_url($filepath);
$filepath = drupal_realpath($parsed_url['path']);
// Load the JavaScript file.
$file = file_get_contents($filepath);
At https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_... api.drupal.org on drupal.parse.url states:
This function should only be used for URLs that have been generated by the system, such as via url(). It should not be used for URLs that come from external sources, or URLs that link to external resources.
Comment | File | Size | Author |
---|---|---|---|
#10 | core-filename-cannot-be-empty-locale-2163439-10.patch | 695 bytes | Mike Lewis |
Comments
Comment #1
SocialNicheGuru CreditAttribution: SocialNicheGuru commentedjust wonder if the code checks for the external flag on urls. if so many urls don't set it. google just in case.
Comment #2
SocialNicheGuru CreditAttribution: SocialNicheGuru commentedAm I thinking about this in the right way or would the strpos add to much of a lag? is there a better way to exclude external scripts from the drupal_parse_url function?
Comment #3
SocialNicheGuru CreditAttribution: SocialNicheGuru commentedComment #4
nicobot CreditAttribution: nicobot commentedI'm not sure how you get this error, since file_get_contents() should receive at least a string with the path.
Even though, drupal_parse_url() is able to handle external script files, it's true that GET parameters might change the content of a script file (as you pointed with gmaps and its libraries); so the parsing is not being done correctly.
But, I also think that some external files (again, as pointed out, like gmaps) should not be processed by locale since they might not be localizable.
So it would be nice to have a way of selecting JS files to be excluded of this processing, as it incurs on a waste of time and resources in the backend affecting the page load time.
As a proposal, all external libraries could be excluded and just if needed, the programmer can make a drupal_add_js() for an external file also indicating it as "localizable". Or a less aggressive change could be to mark external libraries as "not_localizable".
If we have an agreement, I don't mind to make a patch for this.
Comment #5
pinoniq CreditAttribution: pinoniq commentedWe currently have a similar problem. The following error is occurring:
failed to open stream: No such file or directory in _locale_parse_js_file
This because the file being added is an external one that needs the query parameters to be added.
Having an option in drupal_add_js 'localize' => 'false' that defaults to true seems to be the way forward here.
Has there been any work done so far?
Comment #6
pinoniq CreditAttribution: pinoniq commentedComment #7
jmdorian CreditAttribution: jmdorian at QSEO commentedI have same problem too,when using query-parameters in url of external JS library.
+1 to an option like "localize".
Comment #8
jmdorian CreditAttribution: jmdorian at QSEO commentedComment #9
berramou CreditAttribution: berramou commentedI fix this by pathing includes/locale.inc :
Comment #10
Mike Lewis CreditAttribution: Mike Lewis at Duo is now part of Mediacurrent! commentedI've rolled #9 as a patch:
Comment #11
Mike Lewis CreditAttribution: Mike Lewis at Duo is now part of Mediacurrent! commentedComment #13
berramou CreditAttribution: berramou commentedComment #14
DamienMcKennaPatch #13 is exactly the same as #10.