With a configuration of several domains and languages, I found that the thumbnails or other style images used in Views were not created. I found that switching off Domain Locale, the images were created. I found that it was related to URLs of images having the character "?". The domains which were affected were those who didn't have one language (Spanish) which was set to the original language when installing Drupal. The configuration which exhibits the problem is:

  1. Domain with different languages to the default main configuration site (before Domain Access and Domain Locale installation).
  2. Default language in (1) different from English.
  3. Clean URLs active.
  4. Views and Views Domain active
  5. Affected images: those which have a Style Image and thus are created on-the-fly and not submission of node create form.

The behaviour can be replicated (and is related to the problem above) by visiting:

www.example.com/?q=user

If the domain shows the login screen, there is no problem. If it is redirected to homepage or elsewhere, the domain is affected by a possible bug in Domain Locale.

Comments

Drupipi created an issue. See original summary.

Drupipi’s picture

I have apparently solved this issue by making the following exception: in the init method, I make an exception to the drupal_goto if the URL of the HTTP resource contains ".jpg", ".png". in the appropriate position (end of URL before any ?, #, &). It is not elegant, but works perfectly with no apparent side effects, and still retains the functionality of redirection when you try to visit a node in the default language, and the language is not set as one of the allowed ones for that specific domain.

michiellucas’s picture

I to had this problem, fixed it with a check on the default file path. Created patch

Drupipi’s picture

michiellucas, in my version of the module, the lines read different to what you put as - (delete line). I already have

$language_default = domain_locale_language_default();

and also already have

drupal_goto($http . $_domain['subdomain'] . $url_suffix);

with $url_suffix being $language_default->prefix, which is equivalent to your code, and functionally identical.

And still have the problem, with the only solution applying the drupal_goto exception for images.

mac_weber’s picture

Do this bug happen if there is a language prefix for all languages?
My recommendation is to ALWAYS use language prefix on ALL LANGUAGES, this avoids lots of bugs.

Drupipi’s picture

Yes, I have activated prefixes (in reality, suffixes, i.e. www.example.com/en, www.example.com/ru, etc.) for all languages. I think the problem lies in Spanish being the default language for all the sites (core configuration previous to Domain Access and Domain locale installation). Somehow this makes that if a domain is not assigned that language, the bug, because it seems a bug, makes that the image cannot be created. What I am not sure if it is a bug of the core (image thumbnail creation) or this module or some incompatibility of both. I solved by using the lines in my reply, which is, of course, a temporary and very limited solution. The problem is serious: I could not have thumbnails for my views in other languages in domains not having Spanish assigned in Domain Locale !!!

mac_weber’s picture

Status: Active » Needs work

@Drupipi thank you for the patch. I think we need more people to test this patch before merging.

Things I'm afraid of:
- The first versions of D7 Domain Locale did not lock the options at the page admin/structure/domain/view/language. All language settings must be done at /admin/structure/domain/view/[domain_id]/language. I'm afraid the first people which may had modified these options at that time are the ones facing this issue.

- I'm not sure how this patch will affect sites which are already working fine. Maybe it creates double language path prefix?

- Probably we should write an update hook to make sure all languages are enabled under the hood, as need. This already done today at the installation. http://cgit.drupalcode.org/domain_locale/tree/domain_locale.install?id=f...

Try removing the changes you had done and running code to update the database to enable all languages, as done at the hook_install. Let me know if it works for you. If you write this code, please send a patch.

Drupipi’s picture

Issue summary: View changes
Drupipi’s picture

@Mac_Weber, I didn't send the patch, it was done by @michiellucas.
I tested the patch and didn't work for me. For me, it only works the temporary solution, which only corrects the problem with thumbnails. Any other problem related to this possible bug may be not corrected.

I will try the changes when I have some time.

kumkum29’s picture

Hello,

i have the same problem on several subdomains.
If I define only one language on these subdomains, the images aren't generated. If I choose all the available languages for these subdomains, the images are created.

I use the version 7.x-1.0-beta5.

Drupipi have you found a solution?

Thanks for your help. Perhaps have you a temporary solution to resolve this problem?

P.S. The code in the patch#3 seems to be the same in the 7.x-1.0-beta5 version...

Drupipi’s picture

Well, kumkum29, my solution was just a temporary one, crafted particularly to correct the specific problem, which seems exactly what happens to you, also.

So I changed the following file:

In sites/all/modules/domain_locale/domain_locale.module

in the function domain_locale_init() -- around line 242, depending on version

I add the following code, after the line that reads: $url_suffix = ''; }
CAUTION: Paste the code AFTER the closing parenthesis. Preceding lines included for clarity:
The code will detect if the resource is an image (png, jpg, gif) and will redirect to the home page, in any other case. So for images, it will stay and then display the image.
If you have any problem, please contact me. Also, if you solve your problem with this code, please let me know. Thanks!!!

else {
        $url_suffix = '';
      }
	  // BEGIN adaptation, copy from this line to the end of the line.
	  $flag = true;
	  if(strpos(".." . $_SERVER['REQUEST_URI'], ".png") > 0 ) $flag = false;
	  if(strpos(".." . $_SERVER['REQUEST_URI'], ".jpg") > 0 ) $flag= false;
	  if(strpos(".." . $_SERVER['REQUEST_URI'], ".jpeg") > 0 ) $flag = false;
	  if(strpos(".." . $_SERVER['REQUEST_URI'], ".gif") > 0 ) $flag = false;
      if($flag) drupal_goto($http . $_domain['subdomain'] . $url_suffix);
      // END you finish the selection and copy here.
kumkum29’s picture

Hello Drupipi,

My problem is resolved with your code ! THANKS !!!!

Can we include this code in a future version of the module?

Thanks.

Drupipi’s picture

I am glad that it solved the problem.

As for the code, I think it would be better to fix the problem, this is more a patch than a real fix.

In any case, it should be "cleaned", something like this (not tested) or some more "pro" code:

$img_extensions = array("png", "jpg", "jpeg", "gif");
foreach($img_extensions as $ext){
       $flag = strpos($_SERVER['REQUEST_URI'], "." . $ext) === false);
} // foreach
 if($flag) drupal_goto($http . $_domain['subdomain'] . $url_suffix);
kumkum29’s picture

there is a real problem with the enabled languages and your fix can be improved.

Can we have a reply by the maintainers for to know if this problem can be resolved in a future release?

Thanks.

mac_weber’s picture

Priority: Critical » Major
Issue tags: -thumbnail image style default language

@kumkum29 I am maintainer of this module but currently I am only testing patches other developers send to check if they should be merged because I do not have any ongoing paid project with Domain Locale and right now I need to focus on paid projects.

If any person or any company is willing to hire my time to investigate this issue I would love to work on it. Otherwise, I will wait for someone else to send a definitive working solution to be tested and merged.

Changing the priority as per Priority levels of issues

stevendeleus’s picture

I ran into this problem and solved this by adding $_SERVER['REQUEST_URI'] to the redirect:

<?php
    if ($language_default) {
      $languages = language_list();
      // Get the current prefix
      $current_prefix = $language->prefix;
      // Set the current language to the default language.
      $language = $languages[$language_default->language];
      // Check if we are on a secure connection.
      if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) {
        $http = 'https://';
      }
      else {
        $http = 'http://';
      }
      // Set URL suffix to the language prefix, if available.
      if (isset($language_default->prefix)) {
        $url_suffix = '/' . $language_default->prefix;
      }
      else {
        $url_suffix = '';
      }
      
      $request = strpos($_SERVER['REQUEST_URI'], $current_prefix) === 0 ? substr($_SERVER['REQUEST_URI'], strlen($current_prefix) + 1) : $_SERVER['REQUEST_URI'];

      drupal_goto($http . $_domain['subdomain'] . $url_suffix . $request);
    }
?>
eloivaque’s picture

Hi,

I thinks that the problem is the path is a path internal of drupal, and is created by hook_menu.

/**
 * Implements hook_menu().
 */
function image_menu() {
  $items = array();

  // Generate image derivatives of publicly available files.
  // If clean URLs are disabled, image derivatives will always be served
  // through the menu system.
  // If clean URLs are enabled and the image derivative already exists,
  // PHP will be bypassed.
  $directory_path = file_stream_wrapper_get_instance_by_scheme('public')->getDirectoryPath();
  $items[$directory_path . '/styles/%image_style'] = array(
    'title' => 'Generate image style',
    'page callback' => 'image_style_deliver',
    'page arguments' => array(count(explode('/', $directory_path)) + 1),
    'access callback' => TRUE,
    'type' => MENU_CALLBACK,
  );
  // Generate and deliver image derivatives of private files.
  // These image derivatives are always delivered through the menu system.
  $items['system/files/styles/%image_style'] = array(
    'title' => 'Generate image style',
    'page callback' => 'image_style_deliver',
    'page arguments' => array(3),
    'access callback' => TRUE,
    'type' => MENU_CALLBACK,
  );

I created this patch and solved for me. I don't now is the best solution.

eloivaque’s picture

I created new patch, as the last patch doesn't work correcly. This new patch work perfect about image styles.

mac_weber’s picture

@eloiv I really like your last patch, yet I haven't tested it manually myself.

I see a coding standard that could be improved if you follow these guidelines https://www.drupal.org/coding-standards#linelength

+++ b/sites/all/modules/contrib/domain_locale/domain_locale.module
@@ -247,7 +247,10 @@ function domain_locale_init() {
+    if ($language_default && !(strstr($current_path, $public_file_path) || strstr($current_path, $system_path))) {

When you send the next patch please change the issue status to needs review.

I invite others to test this patch, and when you do so please post the list of modules you are using for translation because different module sets may have different outcomes (Entity Translation, i18n, etc).

hugronaphor’s picture

I can confirm that the patch on #18 fixes the thumbnail generation.
But I'm not sure about:
- You're checking the public file scheme. Can't it be a valid problem for private file directory as well?
- Why do we need to check the system_path? I think the problem it's just about accessing files on the server, while the system/* routes are defined in hoom_menu isn't it?