You are here

function hosting_alias_insert in Hosting 7.4

Same name and namespace in other branches
  1. 5 alias/hosting_alias.module \hosting_alias_insert()
  2. 6.2 alias/hosting_alias.module \hosting_alias_insert()
  3. 7.3 alias/hosting_alias.module \hosting_alias_insert()

Save stored aliases for a new site.

Parameters

Object $node: The node of the site containing the aliases to save.

2 calls to hosting_alias_insert()
hosting_alias_node_insert in alias/hosting_alias.module
Implements hook_node_insert().
hosting_alias_update in alias/hosting_alias.module
Update stored aliases for an existing site.

File

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

Code

function hosting_alias_insert($node) {
  $node->aliases = isset($node->aliases) ? $node->aliases : array();
  $aliases = is_array($node->aliases) ? $node->aliases : explode("\n", str_replace(",", "\n", $node->aliases));
  $automatic = hosting_alias_automatic_aliases(hosting_site_clean_domain($node->title));
  if (empty($aliases) && empty($automatic)) {
    return;
  }
  if (count($aliases)) {
    $aliases = array_unique($aliases);
    foreach ($aliases as $alias) {
      $alias = hosting_site_clean_domain($alias);

      // Only flag custom aliases that aren't automatically generated
      if (in_array($alias, $automatic)) {
        continue;
      }
      $id = db_insert('hosting_site_alias')
        ->fields(array(
        'vid' => $node->vid,
        'nid' => $node->nid,
        'alias' => $alias,
        'automatic' => HOSTING_ALIAS_CUSTOM,
        'redirection' => isset($node->redirection) ? $node->redirection : 0,
      ))
        ->execute();
    }
  }
  if (count($automatic)) {
    foreach ($automatic as $alias) {
      $alias = hosting_site_clean_domain($alias);

      // Only insert valid FQDNs.
      if (!_hosting_valid_fqdn_wildcard($alias)) {
        continue;
      }
      $id = db_insert('hosting_site_alias')
        ->fields(array(
        'vid' => $node->vid,
        'nid' => $node->nid,
        'alias' => $alias,
        'automatic' => HOSTING_ALIAS_AUTOMATIC,
        'redirection' => isset($node->redirection) ? $node->redirection : 0,
      ))
        ->execute();
    }
  }
}