You are here

function _domain_alias_link in Domain Access 6.2

Same name and namespace in other branches
  1. 7.3 domain_alias/domain_alias.module \_domain_alias_link()
  2. 7.2 domain_alias/domain_alias.module \_domain_alias_link()

Format links for the switcher block.

Parameters

$alias: The alias array to check.

$domain: The parent domain of the alias.

$request: A reversed array of the HTTP_HOST request, used for replacement strings.

$active: The active alias id, if present.

Return value

A link or plain text representation of the alias.

1 call to _domain_alias_link()
theme_domain_alias_block in domain_alias/domain_alias.module
Theme element for the Domain Alias switcher block.

File

domain_alias/domain_alias.module, line 446
Interface for advanced domain matching for Domain Access.

Code

function _domain_alias_link($alias, $domain, $request, $active = 0) {

  // Search for wildcards.
  $wildcard = substr_count($alias['pattern'], '*');
  $character = substr_count($alias['pattern'], '?');
  $text = $alias['pattern'];
  if ($wildcard) {
    $bits = array_reverse(explode('.', $text));
    foreach ($bits as $key => $bit) {
      if ($bit == '*' && isset($request[$key])) {
        $bits[$key] = $request[$key];
      }
    }
    $text = implode('.', array_reverse($bits));
  }
  if ($character) {
    $request = strrev(implode('.', array_reverse($request)));
    $char = strpos(strrev($text), '?');
    $replace = substr($request, $char, 1);
    $text = str_replace('?', $replace, $text);
  }
  $wildcard = substr_count($text, '*');
  $output = $alias['pattern'];
  if ($alias['alias_id'] == $active) {
    $output = '<em>' . $alias['pattern'] . '</em>';
  }
  if (!$alias['redirect'] && !$wildcard) {
    $domain['subdomain'] = $text;
    $path = domain_get_uri($domain);
    $link = l($output, $path, array(
      'absolute' => TRUE,
      'html' => TRUE,
    ));
  }
  else {
    $link = check_markup($output);
  }
  return $link;
}