function spaces_load in Spaces 6
Same name and namespace in other branches
- 5.2 spaces.module \spaces_load()
- 6.3 spaces.module \spaces_load()
- 6.2 spaces.module \spaces_load()
- 7.3 spaces.module \spaces_load()
- 7 spaces.module \spaces_load()
Load a space.
Parameters
$type: The type of the space to be loaded. Must be one of the keys in the array returned by spaces_types().
$sid: The id of the space to be loaded. If omitted, a "prototype" space will be constructed.
$is_active: Optional boolean flag for whether this space is active or not. Defaults to FALSE.
Return value
The requested space object or FALSE if something went wrong.
11 calls to spaces_load()
- spaces_init_context in ./spaces.module 
- Context prefix provider callback.
- spaces_og_nodeapi in spaces_og/spaces_og.module 
- Implementation of hook_nodeapi().
- spaces_preset_form in ./spaces_admin.inc 
- Form for adding or editing a spaces preset.
- spaces_site_init in spaces_site/spaces_site.module 
- Implementation of hook_init().
- spaces_taxonomy_form_alter in spaces_taxonomy/spaces_taxonomy.module 
File
- ./spaces.module, line 919 
Code
function spaces_load($type, $sid = NULL, $is_active = FALSE) {
  $types = spaces_types();
  if (isset($types[$type])) {
    $class = $types[$type]['class'];
    // Create a new space object
    $space = new $class($type, $sid, $is_active);
    // Initialize various space variables
    $space->type = $type;
    $space->features = array();
    $space->settings = array();
    $space->customizer = array();
    // Initialize space specific settings if $sid is provided
    if ($sid) {
      $space->sid = $sid;
      // Load the PURL modifier
      if ($modifier = purl_load(array(
        'provider' => "spaces_{$type}",
        'id' => $sid,
      ))) {
        $space->purl = $modifier['value'];
      }
      // Load features
      $result = db_query("SELECT id, value FROM {spaces_features} WHERE sid = %d AND type = '%s' ORDER BY weight ASC", $sid, $type);
      while ($row = db_fetch_object($result)) {
        $space->features[$row->id] = $row->value;
      }
      // Load settings
      $result = db_query("SELECT id, value FROM {spaces_settings} WHERE sid = %d AND type = '%s'", $sid, $type);
      while ($row = db_fetch_object($result)) {
        $space->settings[$row->id] = unserialize($row->value);
      }
      // Load customizer & preset
      $row = db_fetch_object(db_query("SELECT customizer, preset FROM {spaces} WHERE sid = %d AND type = '%s'", $space->sid, $space->type));
      $space->customizer = $row->customizer ? unserialize($row->customizer) : array();
      // Enforce preset or use default if not found
      $default_presets = variable_get('spaces_default_presets', array());
      if ($row->preset) {
        $space->preset = $row->preset;
      }
      else {
        if (empty($space->preset) && isset($default_presets[$type])) {
          $space->preset = $default_presets[$type];
        }
      }
      if (!empty($space->preset)) {
        spaces_preset_enforce($space);
      }
    }
    return $space;
  }
  return false;
}