Hi all,

I have a suggestion for the use of Source domain.

Lets assume you have some domains and you share content over all domains. But you want only one node to be avilable only at one domain. Teasers are available on all domains.

I select "Send to all affiliates". And I also check the source domain to be e.g. domain B. So all links direct to domain B.
But that does not prevent, that the node is available also on domain A and C. That is not quite good.

In short words: I want to have teasers and data available over all sites. But the node should only be available on the Source domain.

Additionally an 301 could redirect to the correct domain.

I think that would be an important feature with less effort to implement. What do you think about it?

Kind regards
Jan

Comments

jan.s’s picture

Status: Active » Closed (duplicate)
jan.s’s picture

function hook_init() {
	
	global $_domain;
	
	if ($node = menu_get_object()) {
		$domains = domain_get_node_domains($node->nid);
		if (!in_array($_domain['domain_id'], $domains['domain_id'])) {
			$sourceDomain = domain_source_lookup($node->nid);
			domain_goto($sourceDomain);
		}
	}
}
jan.s’s picture

To do a 301 redirect:

function hook_init() {
	
	global $_domain;
	
	if ($node = menu_get_object()) {
		$domains = domain_get_node_domains($node->nid);
		if (!in_array($_domain['domain_id'], $domains['domain_id'])) {
			$sourceDomain = domain_source_lookup($node->nid);
			
			//domain_goto($sourceDomain);
			
			if ($sourceDomain != -1 && $_domain['domain_id'] != $sourceDomain['domain_id']) {
				$path = domain_get_uri($sourceDomain);
				drupal_goto($path, array(), 301);
			}
		}
	}
}

See: http://drupal.org/node/772406

ozalee’s picture

Hi jan.s
How do you implement this?

ozalee’s picture

Tried to put it in a module,renaming the function. No success.

ozalee’s picture

Ok, i just put the code at the top of my node--product.tpl.php.
Probably not the best way.
Any advice welcome.

jan.s’s picture

Hi ozalee,

I put this code in an own module ("multidomain"). So the function must be named "function multidomain_init()".

Have you cleared the cache after updating your module so that the init hook was registered?
Its working fine for me.

ozalee’s picture

The above code didn't work for me anymore since I-don't-remember-which release.
Took me a long time to get it working again as i'm a noob with php.

function hook_init() {
  if ($node = menu_get_object()) {
        $current_domain = domain_get_domain();
        $domains = domain_get_node_domains($node->nid);
        if (!in_array($current_domain['domain_id'], $domains['domain_id'])) {
            $sourceDomain = $node->domain_source;   
            $sourceDomain2 = domain_lookup($sourceDomain);
            //domain_goto($sourceDomain2);
            
            if ($sourceDomain2['domain_id'] != -1 && $current_domain['domain_id'] != $sourceDomain2['domain_id']) {
                $path = domain_get_uri($sourceDomain2);
                drupal_goto($path, array(), 301);
            }
        }
  }
}     

Hope this helps someone.
If anyone finds a mistake, i'm all ears.

ozalee’s picture

Better (for the "Available on all domains nodes"):

function domain_node_redirect_init() {
  if ($node = menu_get_object()) {
        $current_domain = domain_get_domain();
        $domains = domain_get_node_domains($node->nid);
        if (!in_array($current_domain['domain_id'], $domains['domain_id'])) {
            $sourceDomain = $node->domain_source;   
            $sourceDomain2 = domain_lookup($sourceDomain);
            //domain_goto($sourceDomain2);
            
            if ($sourceDomain2['domain_id'] > 0 && $current_domain['domain_id'] != $sourceDomain2['domain_id']) {
                $path = domain_get_uri($sourceDomain2);
                drupal_goto($path, array(), 301);
            }
        }
  }
}
mattwmc’s picture

Is there a D6 version of this anywhere?

Update: This seems to be working: https://drupal.org/node/704568

lundj’s picture

Issue summary: View changes

Hi!

I think the code of comment #9 is not valid anymore... maybe because of the newest version of domainaccess?

The source code line
$sourceDomain = $node->domain_source;
became
$sourceDomain = array_shift(array_values($node->domains));

in my case - now it works like a charm.

joelrotelli’s picture

@lundj You're right

Yes, the working code is :

$current_domain = domain_get_domain();
    $domains = domain_get_node_domains($node->nid);
    if (!in_array($current_domain['domain_id'], $domains['domain_id'])) {
      $sourceDomain = array_shift(array_values($node->domains));
      $sourceDomain2 = domain_lookup($sourceDomain);
      //domain_goto($sourceDomain2);
      if ($sourceDomain2['domain_id'] > 0 && $current_domain['domain_id'] != $sourceDomain2['domain_id']) {
        $path = domain_get_uri($sourceDomain2);
        drupal_goto($path, array(), 301);
      }
    }

if ($node = menu_get_object()) { does not work if the node is not allowed to be displayed on the current domain. You have to check if you are on a node, for exemple with : if(arg(0) == 'node' && is_numeric(arg(1)) && $node = node_load(arg(1)))

neilp78’s picture

kobb’s picture

Just wanted to say that the code in #12 is still working as of July '16.

It seems like this should be included in the DA submodule domain_source.

Thanks, @joelrotelli & @ozalee