function hosting_alias_insert

7.x-3.x hosting_alias.module hosting_alias_insert($node)

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 238
Allow sites to have domain aliases that they can be accessed with.

Code

function hosting_alias_insert($node) {
  $automatic = hosting_alias_automatic_aliases(strtolower(trim($node->title)));
  if (!empty($node->aliases) || count($automatic)) {
    $aliases = (is_array($node->aliases)) ? $node->aliases : explode("\n", str_replace(",", "\n", $node->aliases));
    if (is_array($aliases)) {
      foreach ($aliases as $alias) {
        if (($alias = trim($alias)) && !in_array($alias, $automatic)) {
          $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) {
        if (($alias = trim($alias)) && _hosting_valid_fqdn_wildcard($alias)) {
          $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();
        }
      }
    }
  }
}