You are here

function hosting_alias_nodeapi in Hosting 6.2

Same name and namespace in other branches
  1. 5 alias/hosting_alias.module \hosting_alias_nodeapi()

Implementation of hook_nodeapi().

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

File

alias/hosting_alias.module, line 344
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 = $node->aliases;
        foreach ($aliases as $alias) {
          if (!module_exists('hosting_subdirs')) {
            hosting_alias_validate_alias($node, $alias);
          }
        }

        // Make sure chosen redirect is still an alias
        if ($node->redirection != 0 && !in_array($node->redirection, $aliases) && !($node->redirection == $node->title)) {
          form_set_error('redirection', t('The domain name @alias is not an alias for this site.', array(
            '@alias' => $node->redirection,
          )));
        }
        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 Target'),
            '#value' => !empty($redirection) ? l($redirection, "http://{$redirection}") : t('None'),
            '#weight' => 10,
          );
        }
        break;
    }
  }
}