function domain_block in Domain Access 5
Same name and namespace in other branches
- 6.2 domain.module \domain_block()
Implement hook_block()
A nifty little domain-switcher block, useful during debugging.
File
- ./
domain.module, line 200 - Core module functions for the Domain Access suite.
Code
function domain_block($op = 'list', $delta = 0, $edit = array()) {
global $_domain, $base_url;
$blocks = array();
switch ($op) {
case 'list':
$blocks[0] = array(
'info' => t('Domain switcher'),
);
$blocks[1] = array(
'info' => t('Domain access information'),
);
return $blocks;
break;
case 'view':
switch ($delta) {
case 0:
$block['subject'] = t('Domain switcher');
$items = array();
$domains = domain_domains();
$msg = FALSE;
foreach ($domains as $domain) {
if ($domain['valid']) {
$title = $domain['sitename'];
$allow = TRUE;
}
else {
$title = $domain['sitename'] . ' *';
$allow = FALSE;
if (user_access('administer domains')) {
$msg = TRUE;
$allow = TRUE;
}
}
if ($allow) {
$items[] = l($title, domain_get_uri($domain));
}
}
$block['content'] = theme('item_list', $items);
if ($msg) {
$block['content'] .= t('<em>* Inactive domain.</em>');
}
break;
case 1:
$block['content'] = '';
if (arg(0) == 'node' && is_numeric(arg(1))) {
$block['subject'] = t('Domain access information');
$this_node = node_load(arg(1));
$output = '';
if (!empty($this_node->subdomains)) {
$items = array();
foreach ($this_node->subdomains as $name) {
$items[] = check_plain($name);
}
$output .= theme('item_list', $items, t('Subdomains'));
}
if (!empty($this_node->editors)) {
$items = array();
foreach ($this_node->editors as $name) {
$items[] = check_plain($name);
}
$output .= theme('item_list', $items, t('Editors'));
}
if (isset($this_node->domain_source)) {
$this_domain = domain_lookup($this_node->domain_source);
$output .= theme('item_list', array(
check_plain($this_domain['sitename']),
), t('Source domain'));
}
if (empty($output)) {
$output = t('This node is not assigned to a domain.');
}
$block['content'] = '<p>' . t('%node is published with the following Domain Access rules:', array(
'%node' => $this_node->title,
)) . '</p>' . $output;
}
return $block;
break;
}
return $block;
break;
}
}