View source
<?php
define('DOMAIN_NAV_MENU', TRUE);
function domain_nav_init() {
drupal_add_css(drupal_get_path('module', 'domain_nav') . '/domain_nav.css');
}
function domain_nav_menu() {
$items = array();
if (DOMAIN_NAV_MENU == TRUE) {
$root = domain_default();
$items['domain'] = array(
'title' => 'Domain',
'type' => MENU_SUGGESTED_ITEM,
'page callback' => 'drupal_goto',
'page arguments' => array(
$root['path'],
),
'access callback' => 'domain_nav_check',
'access arguments' => array(
TRUE,
),
'description' => 'Go to main site',
);
$domains = domain_domains();
foreach ($domains as $domain) {
$type = MENU_NORMAL_ITEM;
if (empty($domain['valid'])) {
$type = MENU_SUGGESTED_ITEM;
}
$items['domain/' . filter_xss_admin($domain['subdomain'])] = array(
'title' => check_plain($domain['sitename']),
'type' => $type,
'page callback' => 'drupal_goto',
'page arguments' => array(
$domain['path'],
),
'access callback' => 'domain_nav_check',
'access arguments' => array(
TRUE,
),
'description' => 'Go to ' . filter_xss_admin($domain['subdomain']),
);
}
}
return $items;
}
function domain_nav_check($access = FALSE) {
return $access;
}
function domain_nav_perm() {
return array(
'access domain navigation',
);
}
function domain_nav_theme() {
$themes = array(
'domain_nav_default' => array(
'arguments' => array(
'options' => array(),
),
),
'domain_nav_ul' => array(
'arguments' => array(
'options' => array(),
),
),
'domain_nav_menus' => array(
'arguments' => array(
'options' => array(),
),
),
);
return $themes;
}
function domain_nav_block($op = 'list', $delta = 0, $edit = array()) {
$block = array();
switch ($op) {
case 'list':
$block[0]['info'] = t('Domain list navigator');
break;
case 'view':
$block['subject'] = '';
$block['content'] = domain_nav_render();
break;
case 'configure':
$form['domain_nav_block'] = array(
'#type' => 'radios',
'#title' => t('Link paths'),
'#default_value' => variable_get('domain_nav_block', 0),
'#options' => array(
0 => t('Link to site home page'),
1 => t('Link to active url'),
),
);
$options = array(
'default' => t('JavaScript select list'),
'menus' => t('Menu-style tab links'),
'ul' => t('Unordered list of links'),
);
$form['domain_nav_theme'] = array(
'#type' => 'radios',
'#title' => t('Link theme'),
'#default_value' => variable_get('domain_nav_theme', 'default'),
'#options' => $options,
);
return $form;
break;
case 'save':
variable_set('domain_nav_block', $edit['domain_nav_block']);
variable_set('domain_nav_theme', $edit['domain_nav_theme']);
break;
}
return $block;
}
function domain_nav_render($paths = NULL, $style = NULL) {
global $_domain;
if (!user_access('access domain navigation')) {
return;
}
if (empty($paths)) {
$paths = variable_get('domain_nav_block', 0);
}
if (empty($style)) {
$style = variable_get('domain_nav_theme', 'default');
}
$options = array();
$domains = domain_domains();
$paths == 0 ? $func = 'domain_get_path' : ($func = 'domain_get_uri');
foreach ($domains as $key => $value) {
$allow = TRUE;
if (!$value['valid']) {
if (user_access('access inactive domains')) {
$value['sitename'] .= ' *';
}
else {
$allow = FALSE;
}
}
if ($allow) {
if ($_domain['subdomain'] == $value['subdomain']) {
$value['active'] = TRUE;
}
$path = $func($value);
$value['path'] = $path;
$extra = array();
$extra = module_invoke_all('domainnav', $value);
$value = array_merge($value, $extra);
$options[$value['domain_id']] = $value;
}
}
$theme = 'domain_nav_' . $style;
drupal_alter('domain_nav_options', $options);
$content = theme($theme, $options);
return $content;
}
function theme_domain_nav_default($options) {
global $_domain;
$current = $options[$_domain['domain_id']];
$output = '<form class="domain-list" action=""><div class="domain-pointless-validator-class">';
$output .= '<select onchange="if (this.value) location.href=this.value;">';
$output .= '<option value="' . $current['path'] . '">' . t('Jump to...') . '</option>';
foreach ($options as $key => $value) {
isset($value['active']) ? $selected = ' selected="selected"' : ($selected = '');
$output .= '<option value="' . $value['path'] . '"' . $selected . '>' . filter_xss_admin($value['sitename']) . '</option>';
}
$output .= '</select>';
$output .= '</div></form>';
return $output;
}
function theme_domain_nav_ul($options) {
foreach ($options as $key => $value) {
isset($value['active']) ? $active = 'active' : ($active = '');
$class = "domain-id-" . $value['domain_id'] . " " . $active;
$items[] = l($value['sitename'], $value['path'], array(
'attributes' => array(
'class' => $class,
),
));
}
return theme('item_list', $items);
}
function theme_domain_nav_menus($options) {
foreach ($options as $key => $value) {
isset($value['active']) ? $active = 'active' : ($active = '');
$items[] = array(
'data' => l($value['sitename'], $value['path']),
'class' => "domain-id-" . $value['domain_id'] . " " . $active,
);
}
return theme('item_list', $items, NULL, 'ul', array(
'class' => 'tabs primary',
));
}
function domain_nav_domainupdate($op, $domain, $form_state = array()) {
if (DOMAIN_NAV_MENU == TRUE) {
menu_rebuild();
}
}