Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dealancer’s picture

Sorry, It should be

<img src="http://foo.com/sites/default/files/something">

instead of

<img src="http://foo.com/ru/sites/default/files/something">
dealancer’s picture

Status: Active » Patch (to be ported)
FileSize
329 bytes

Patched, this works for me.

Please test it and implement.

Garrett Albright’s picture

Huh. Do you have private downloads turned on? I can't see why this would be happening otherwise.

dealancer’s picture

I have many modules enebled, but not this.

Would this patch work good on "empty" Drupal installation?

havok’s picture

Hi, thanks for this great module.

I'm having this problem too. I'm on a multi-language site, when my users edit the content and then save it again, all the images get broken. The full path of the image is replaced to the full path + the language prefix of the user.

I'll test that patch and post my results here.

Thanks in advance for any advice.

Garrett Albright’s picture

havok, same question for you - are you using private downloads, by any chance?

havok’s picture

Hi Garrett, thanks for your time,

By private downloads do you mean this: http://drupal.org/project/private_download

No, I didn't even know about that module.

Thanks in advance.

Garrett Albright’s picture

No, I mean, if you go to Administer > Site configuration > File system, under the "Download method" section, do you have "Public" or "Private" selected?

havok’s picture

Ah, ok. No.

"Public - files are available using HTTP directly." is selected.

Kind regards

havok’s picture

FileSize
114.61 KB
58.39 KB

I'm attaching screenshots on the issue. One shows the original URL and the other shows the result after the filter.

Thanks in advance for the help.

Garrett Albright’s picture

I'm really confused. In order for this to be happening, Drupal has to think the path to the file is a menu item:

  if (menu_get_item($parts['path'])) {
    global $language;
  }
  else {
    $language = NULL;
  }

And when I test things, I can't get that to happen with things using a standard file path.

Might you have any other download-related modules installed on the site? Perhaps one is defining the files directory path as a path to be handled by it…

havok’s picture

I was able to isolate the problem to Pathologic removing all the filters. The site doesn't have download related-modules, just i10n and rich editor modules.

This is how to reproduce:

Install i18n and lang_dropdown, and pathlogic off-course. Add several languages to the Drupal installation. Add the filter to the default input format. Then, create a content with the user in "English", insert and image link and safe. Image looks good. Now change the language to "Whatever" on the drop down menu, edit the node, add some words (to actually force the system to update the node) and safe. Image get broken with the prefix of the language the user is in. Change the language again to something not English and repeat the process, you get the image changed to the language of the user.

By the way, I'm having this as the "also consider local":

http://libreofficeaustralia.org/
/

Kind regards.

havok’s picture

I've tested the patch of #2 by dealancer and it fixes the problem. But I really would like to understand the problem first before recommend that patch.

That patch removes the
"$language = NULL;" statement and replace it by "$language = language_default();" , that is, the statement when the item is NOT a menu item (I say so in relation to #11).

Kind regards.

dealancer’s picture

Garrett Albright, I'm also using public download method.

havok, Garrett Albright, then Pathologic calls url(...) function (http://api.drupal.org/api/drupal/includes--common.inc/function/url)


return $matches[1] . '="' . url(
    $parts['path'],
    array(
      'query' => $qparts,
      'fragment' => isset($parts['fragment']) ? $parts['fragment'] : NULL,
      'absolute' => $absolute,
      'language' => $language,
    )
  ) . '"';

In url function there is a call to language_url_rewrite(...) func (http://api.drupal.org/api/drupal/includes--language.inc/function/languag...).

  // May need language dependent rewriting if language.inc is present.
  if (function_exists('language_url_rewrite')) {
    language_url_rewrite($path, $options);
  }

It overrides $language if it is not set.

 global $language;

  // Only modify relative (insite) URLs.
  if (empty($options['external'])) {

    // Language can be passed as an option, or we go for current language.
    if (!isset($options['language'])) {
      $options['language'] = $language;
    }

So here is a reason of this problem. May you should play with external parameter to avoid this issue.

havok’s picture

Ohh, that makes sense :D

Thanks dealancer

Garrett Albright’s picture

FileSize
1.51 KB

Well done, dealancer. Thanks for your research. It would have definitely taken me a while to figure that out…

dealancer, havok, could you try this patch?

leeyuiwah’s picture

I had a bilingual site and I had the same problem. I tested the patch of #16 and it works! Thanks!

Garrett Albright’s picture

Status: Patch (to be ported) » Fixed

Made a new release with the patch in #16. Thanks, everyone, and please let me know if you find any more problems.

pfournier’s picture

Hi,
I just ran into the same problem; I had a look at the patch in #16; I find it a bit invasive, as it modifies (temporarily) a global variable to achieve its goal.

I would like to propose an alternative patch, even though the issue is marked as fixed.

Patrick

Garrett Albright’s picture

I don't really like the idea of building the URL "manually" like that, but you're right in that modifying global variables like that is pretty crappy and below my standards. However, it looks like NaX has proposed another solution here which looks like it'll work without stupid variable tricks: #348421: Multilingual links with Pathologic

havok’s picture

Status: Fixed » Postponed

The current path works summited by Garrett ok, but I don't like the approach neither.

I'm changing the status of the ticket to postponed then.

Kind regards

zambrey’s picture

Has this issue been addressed in 7.x-branch?
I'm experiencing similar thing on images using 7.x-1.2 verison.

Garrett Albright’s picture

zambrey, could you try installing a dev release version and seeing if it's still happening? Note that you have to edit, change and save some content in order to see the effect of a different input filter take place.

zambrey’s picture

Thanks for reply. The same thing happens with 7.x-1.x-dev.
I will move discussion to #1156720: Multilingual links in D7 as links are broken also.

zambrey’s picture

Hmm, I've done some heavy testing with or without i18n module enabled.
Links to nodes are broken by i18n module (which is now fixed in i18n dev release) but paths to images are broken regardless of i18n.

To reproduce this you only need extra language with prefix and node in that language with image in body.
Like described in #1
sites/default/files/something
becomes
prefix/sites/default/files/something

fietserwin’s picture

I see the same behaviour still occurring in D7. Looking at who attaches the language prefix there in D7 it is locale.inc, function locale_language_url_rewrite_url. I'm not sure that this function should touch url's that point to resources that actually are available on the webserver (thus things like images, js, css).

Questions:
-1- should this function be called at all, or as it gets called indirectly. should url() be called at all?
-2- if so, is this an error in core?

Note:
- marking this as needing forward port, as the issue mentioned in #24 does not look like the D7 version of this problem to me.
- I am thinking about creating an issue in core. If/when I do so, I will cross post here.

fietserwin’s picture

I tried to pass in an empty language object and that worked fin for images but not for other Drupal paths that should be language prefixed

This only works for existing resources, not for internal paths like node/{nid}:

  $language = new stdClass();
  $language->language = LANGUAGE_NONE;
  $language->prefix = '';
  $url = url(
    $parts['path'],
    array(
      'query' => $qparts,
      'fragment' => isset($parts['fragment']) ? $parts['fragment'] : NULL,
      'absolute' => $absolute,
      'language' => $language,
    )
  );

So I guess that this Is an error in core.

fietserwin’s picture

Status: Postponed » Closed (duplicate)

Closing this one as a duplicate of #348421: Multilingual links with Pathologic.