You are here

function spaces_init in Spaces 7.3

Same name and namespace in other branches
  1. 5.2 spaces.module \spaces_init()
  2. 6.3 spaces.module \spaces_init()
  3. 6 spaces.module \spaces_init()
  4. 6.2 spaces.module \spaces_init()
  5. 7 spaces.module \spaces_init()

Implements hook_init().

File

./spaces.module, line 792

Code

function spaces_init() {
  spaces_ahah_check();
  if (module_exists('spaces_customtext')) {
    global $language;
    $language->language = $language->language === 'spaces_customtext' ? spaces_customtext_cache() : $language->language;
  }
  if (!spaces_access_space()) {
    menu_set_active_item('spaces-access-denied');
  }
  spaces_router('init');

  /**
   * If the current menu object is not part of the space, this will
   * redirect it to the correct space.
   *
   * Since the menu returns TRUE in the cases a redirect is needed if
   * the user has access to the item, the object will be stored in the
   * menu for this to fetch and redirect.
   */

  // Can't call menu_get_item in hook_init without this.
  if (variable_get('menu_rebuild_needed', FALSE) || !variable_get('menu_masks', array())) {
    menu_rebuild();
  }

  // Simplist case, get the node.
  if ($object = menu_get_object()) {
    $type = 'node';
  }
  elseif ($object = menu_get_object('comment')) {
    $type = 'node';
    $object = node_load($object->nid);
  }
  elseif (($item = menu_get_item()) && isset($item['map'])) {
    foreach (array_filter($item['map'], 'is_object') as $object) {
      $type = isset($object->nid) ? 'node' : (isset($object->uid) ? 'user' : NULL);
      break;
    }
  }

  // If the space is incorrect, reroute.
  if (isset($type) && !spaces_is_spaces_object($type, $object)) {
    spaces_router($type, $object);
  }
}