function domain_tokens in Domain Access 7.2
Same name and namespace in other branches
- 8 domain/domain.module \domain_tokens()
- 7.3 domain.tokens.inc \domain_tokens()
Implements hook_tokens().
File
- ./
domain.tokens.inc, line 53 - Builds placeholder replacement tokens for domain-related data.
Code
function domain_tokens($type, $tokens, array $data = array(), array $options = array()) {
$sanitize = !empty($options['sanitize']);
$replacements = array();
if ($type == 'domain' && !empty($data['domain'])) {
$domain = $data['domain'];
foreach ($tokens as $name => $original) {
switch ($name) {
case 'id':
$replacements[$original] = $domain['domain_id'];
break;
case 'name':
$replacements[$original] = $sanitize ? check_plain($domain['sitename']) : $domain['sitename'];
break;
case 'url':
$url = domain_url_encode($domain['subdomain']);
$replacements[$original] = $sanitize ? check_plain($url) : $url;
break;
case 'subdomain':
$subdomain_elements = explode('.', $domain['subdomain']);
if (count($subdomain_elements) > 2) {
$subdomain = $subdomain_elements[0];
}
else {
$subdomain = 'www';
}
$subdomain = domain_url_encode($subdomain);
$replacements[$original] = $sanitize ? check_plain($subdomain) : $subdomain;
break;
}
}
}
if ($type == 'current-domain') {
$current_domain = domain_get_domain();
$replacements += token_generate('domain', $tokens, array(
'domain' => $current_domain,
), $options);
}
if ($type == 'default-domain') {
$default_domain = domain_default(FALSE);
$replacements += token_generate('domain', $tokens, array(
'domain' => $default_domain,
), $options);
}
return $replacements;
}