diff --git a/domain.blocks.inc b/domain.blocks.inc new file mode 100644 index 0000000..22915d4 --- /dev/null +++ b/domain.blocks.inc @@ -0,0 +1,160 @@ + TRUE)); + } + } + $items = array('items' => $list); + $output = theme('item_list', $items); + $block = array( + 'subject' => t('Domain switcher'), + 'content' => array( + '#markup' => $output, + ), + ); + return $block; +} + +/** + * Prints information about the current node. + * + * @see domain_block_view() + */ +function domain_block_view_information() { + $output = ''; + $node = menu_get_object(); + if (empty($node->nid)) { + return; + } + // Print the assigned domains. + if (!empty($node->subdomains)) { + $output .= theme('item_list', array('items' => $node->subdomains, 'title' => t('Assigned domains'))); + } + // Print the link source domain. + $this_domain = domain_get_node_match($node->nid); + $output .= theme('item_list', array('items' => array(check_plain($this_domain['sitename'])), 'title' => t('Source domain'))); + if (empty($output)) { + $output = t('This node is not assigned to a domain.'); + } + else { + $output = '

' . t('%node is published with the following Domain Access rules:', array('%node' => $node->title)) . '

' . $output; + } + + $block = array( + 'subject' => t('Domain access information'), + 'content' => array( + '#markup' => $output, + ), + ); + return $block; +} + +/** + * Prints information about the current HTTP request. + * + * @see domain_block_view() + */ +function domain_block_view_server() { + $_domain = domain_get_domain(); + $output = ''; + $header = array(t('Property'), t('Value')); + $rows = array(); + $rows[] = array( + t('HTTP_HOST request'), + check_plain($_SERVER['HTTP_HOST']), + ); + $check = domain_lookup(NULL, $_SERVER['HTTP_HOST']); + $match = t('TRUE'); + if ($check == -1) { + // Specific check for Domain Alias. + if (isset($_domain['active_alias_id'])) { + $match = t('ALIAS: Using alias %id', array('%id' => $_domain['active_alias_id'])); + } + else { + $match = t('FALSE: Using default domain.'); + } + } + $rows[] = array( + t('Domain match'), + $match, + ); + foreach ($_domain as $key => $value) { + if (is_null($value)) { + $value = t('NULL'); + } + elseif ($value === TRUE) { + $value = t('TRUE'); + } + elseif ($value === FALSE) { + $value = t('FALSE'); + } + $rows[] = array( + check_plain($key), + !is_array($value) ? check_plain($value) : _domain_block_print_array($value), + ); + } + $output = theme('table', array('header' => $header, 'rows' => $rows)); + $block = array( + 'subject' => t('Domain server information'), + 'content' => array( + '#markup' => $output, + ), + ); + return $block; +} + +/** + * Prints array data for the server block. + * + * @param $array + * An array of data. Note that we support two levels of nesting. + * + * @return + * A suitable output string. + */ +function _domain_block_print_array($array) { + $items = array(); + foreach ($array as $key => $val) { + $value = 'array'; + if (!is_array($val)) { + $value = check_plain($val); + } + else { + $list = array(); + foreach ($val as $k => $v) { + $list[] = t('@key : @value', array('@key' => $k, '@value' => $v)); + } + $value = implode('
', $list); + } + $items[] = t('@key : !value', array('@key' => $key, '!value' => $value)); + } + return theme('item_list', array('items' => $items)); +} diff --git a/domain.module b/domain.module index 192a8f4..4c1f7f2 100644 --- a/domain.module +++ b/domain.module @@ -339,12 +339,16 @@ function domain_theme($existing, $type, $theme, $path) { */ function domain_block_info() { $blocks = array(); - $blocks['switcher'] = array( - 'info' => t('Domain switcher'), - ); $blocks['information'] = array( 'info' => t('Domain access information'), ); + $blocks['server'] = array( + 'info' => t('Domain access server information'), + 'cache' => DRUPAL_NO_CACHE, + ); + $blocks['switcher'] = array( + 'info' => t('Domain switcher'), + ); return $blocks; } @@ -356,77 +360,13 @@ function domain_block_view($delta = '') { if (empty($delta)) { return; } + module_load_include('inc', 'domain', 'domain.blocks'); $function = 'domain_block_view_' . $delta; if (function_exists($function)) { return $function(); } } -/** - * A nifty little domain-switcher block, useful during debugging. - * - * @see domain_block_view() - */ -function domain_block_view_switcher() { - $output = ''; - $list = 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('access inactive domains')) { - $msg = TRUE; - $allow = TRUE; - } - } - if ($allow) { - $list[] = l($title, domain_get_uri($domain), array('absolute' => TRUE)); - } - } - $items = array('items' => $list); - $output = theme('item_list', $items); - return array( - 'subject' => t('Domain switcher'), - 'content' => $output, - ); -} - -/** - * Prints information about the current node. - * - * @see domain_block_view() - */ -function domain_block_view_information() { - $output = ''; - $node = menu_get_object(); - if (empty($node->nid)) { - return; - } - // Print the assigned domains. - if (!empty($node->subdomains)) { - $output .= theme('item_list', array('items' => $node->subdomains, 'title' => t('Assigned domains'))); - } - // Print the link source domain. - $this_domain = domain_get_node_match($node->nid); - $output .= theme('item_list', array('items' => array(check_plain($this_domain['sitename'])), 'title' => t('Source domain'))); - if (empty($output)) { - $output = t('This node is not assigned to a domain.'); - } - else { - $output = '

' . t('%node is published with the following Domain Access rules:', array('%node' => $node->title)) . '

' . $output; - } - - return array( - 'subject' => t('Domain access information'), - 'content' => $output, - ); -} /** * Implements hook_user_load()