You are here

function domain_block in Domain Access 6.2

Same name and namespace in other branches
  1. 5 domain.module \domain_block()

Implement hook_block()

A nifty little domain-switcher block, useful during debugging.

File

./domain.module, line 308
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'),
      );

      // This block was added after D7 was released, so uses a string delta.
      $blocks['server'] = array(
        'info' => t('Domain access server information'),
        'cache' => BLOCK_NO_CACHE,
      );
      return $blocks;
      break;
    case 'view':

      // The use of mixed-type deltas means these must be checked as strings.
      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('access inactive domains')) {
                $msg = TRUE;
                $allow = TRUE;
              }
            }
            if ($allow) {
              $items[] = l($title, domain_get_uri($domain), array(
                'absolute' => TRUE,
              ));
            }
          }
          $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('Assigned domains'));
            }
            $this_domain = domain_get_node_match($this_node->nid);
            $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;
          }
          break;
        case 'server':
          $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,
          );
          $rows[] = array(
            t('is_default'),
            $_domain['domain_id'] < 1,
          );
          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', $header, $rows);
          $block = array(
            'subject' => t('Domain server information'),
            'content' => $output,
          );
          break;
      }
      return $block;
      break;
  }
}