You are here

function hosting_alias_nodeapi in Hostmaster (Aegir) 6

Implementation of hook_nodeapi().

For most of the $op's we pass of to a help function that does the heavy lifting.

File

modules/hosting/alias/hosting_alias.module, line 205
Allow sites to have domain aliases that they can be accessed with.

Code

function hosting_alias_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
  if ($node->type == 'site') {
    switch ($op) {
      case 'insert':
        hosting_alias_insert($node);
        break;
      case 'update':
        hosting_alias_update($node);
        break;
      case 'delete':
        hosting_alias_delete($node);
        break;
      case 'delete revision':
        hosting_alias_delete_revision($node);
        break;
      case 'validate':
        $aliases = explode("\n", $node->aliases);
        foreach ($aliases as $alias) {
          if ($alias = trim($alias)) {
            if (!hosting_domain_allowed($alias, array(
              'nid' => $node->nid,
            )) || $alias == $node->title) {
              form_set_error('aliases', t('The domain name @alias is already in use', array(
                '@alias' => $alias,
              )));
            }
            if (!_hosting_valid_fqdn($alias)) {
              form_set_error('aliases', t('The domain name @alias is not a valid url', array(
                '@alias' => $alias,
              )));
            }
          }
        }
        break;
      case 'load':

        // XXX: this returns only the first redirection status. it
        // works since they are all set to the same in hook_insert(),
        // but we should return an associative alias => redirection
        // array instead
        $additions['redirection'] = db_result(db_query("SELECT redirection FROM {hosting_site_alias} WHERE vid=%d", $node->vid));

        // Only retrieves custom aliases, as they are all that can be modified.
        $additions['aliases'] = hosting_alias_get_aliases($node, HOSTING_ALIAS_CUSTOM);
        return $additions;
        break;
      case 'view':
        $aliases = hosting_alias_get_aliases($node);
        if (sizeof($aliases)) {
          foreach ($aliases as $link) {
            $links[] = l($link, "http://{$link}");
          }
          $node->content['info']['aliases'] = array(
            '#type' => 'item',
            '#title' => t('Domain aliases'),
            '#value' => implode(', ', $links),
            '#weight' => 10,
          );
          $redirection = db_result(db_query("SELECT redirection FROM {hosting_site_alias} WHERE vid=%d", $node->vid));
          $node->content['info']['redirection'] = array(
            '#type' => 'item',
            '#title' => t('Redirection'),
            '#value' => $redirection['redirection'] ? t('Yes') : t('No'),
            '#weight' => 10,
          );
        }
        break;
    }
  }
}