You are here

spaces_og.module in Spaces 5.2

File

spaces_og.module
View source
<?php

define('SPACES_OG_PRIVATE', 1);
define('SPACES_OG_PUBLIC', 2);

/**
 * Spaces OG must be included after the Spaces module. We check this
 * condition here -- if the check fails, at least we don't break Drupal.
 */
if (function_exists('spaces_menu')) {
  class space_og implements space {
    var $group = NULL;
    var $title = NULL;

    /**
     * Constructor
     */
    function __construct($type, $sid = NULL, $is_active = FALSE) {
      if ($sid) {
        $this->group = node_load($sid);
        $this->title = $this->group->title;
        if ($is_active) {

          // Set the group context on behalf of OG
          og_set_group_context($this->group);

          // Handle theme switching since OG is not prefix aware
          if ($this->group->og_theme) {
            global $custom_theme;
            $custom_theme = $group->og_theme;
          }
        }
      }
      else {
        $this->group = new StdClass();
      }
    }

    /**
     * Implementation of space->save().
     */
    function save() {
      if (!$this->save_once) {
        node_save($this->group);
      }
      return;
    }

    /**
     * Implementation of space->delete().
     */
    function delete() {

      // We do not delete the group node here:
      // 1. to allow the group to remain and perhaps later be re-registered as a space
      // 2. to avoid recursion
      return;
    }

    /**
     * Implementation of space->feature_access().
     */
    function feature_access($feature = NULL) {
      if (isset($this->features[$feature])) {
        $features = spaces_features();
        if (spaces_og_is_member($this->sid)) {
          return true;
        }
        else {
          if ($this->feature[$feature] == SPACES_OG_PUBLIC) {
            return true;
          }
        }
      }
      return false;
    }

    /**
     * Implementation of space->admin_access().
     */
    function admin_access() {
      global $user;
      if ($this->group && og_is_node_admin($this->group)) {
        return true;
      }
      else {
        if (user_access('administer group features') || user_access('administer orgranic groups')) {
          return true;
        }
        else {
          if ($this->group->uid == $user->uid) {
            return true;
          }
        }
      }
      return false;
    }

    /**
     * Implementation of space->feature_options().
     */
    function feature_options() {
      return array(
        SPACES_FEATURE_DISABLED => t('Disabled'),
        SPACES_OG_PRIVATE => t('Private'),
        SPACES_OG_PUBLIC => t('Public'),
      );
    }

    /**
     * Implementation of space->links().
     */
    function links(&$links) {
      $links['subscribe'] = spaces_og_subscription_link();
      if ($this
        ->admin_access()) {
        $links['members'] = array(
          'title' => t('Members'),
          'href' => 'member-list',
          'attributes' => array(
            'class' => 'members',
          ),
        );

        // Add settings link for administering spaces
        $links['settings'] = array(
          'title' => t('Settings'),
          'href' => 'node/' . $this->sid . '/edit',
          'attributes' => array(
            'class' => 'settings',
          ),
        );
      }
    }

    /**
     * Implementation of space->form().
     */
    function form() {

      // Only show group form options on preset form
      if (!$this->sid) {

        // Stupid OG will only set values when the node object has a nid set
        $old_gid = $this->group->nid;
        $this->group->nid = -1;

        // Generate OG settings form
        $form = og_group_form($this->group);
        if (module_exists('og_access')) {
          drupal_add_js(drupal_get_path('module', 'og_access') . '/og_access.js');
          og_access_alter_group_form($form, $this->group);
        }
        $this->group->nid = $old_gid;

        // Omit description & theme selection
        unset($form['og_description']);
        unset($form['themes']);

        // Pack the form into a fieldset
        $form['#title'] = t('Group settings');
        $form['#type'] = 'fieldset';
        return $form;
      }
    }

    /**
     * Implementation of space->preset_validate().
     */
    function validate($values) {

      // No need to validate
      return;
    }

    /**
     * Implementation of space->preset_submit().
     */
    function submit($values) {

      // Only process group form options on preset form
      if (!$this->sid) {
        $preset = array();
        $preset['og_selective'] = $values['og_selective'];
        $preset['og_register'] = $values['og_register'];
        $preset['og_directory'] = $values['og_directory'];
        $preset['og_private'] = $values['og_private'];
        return $preset;
      }
      return array();
    }

    /**
     * Implementation of space->preset_enforce().
     */
    function preset_enforce($preset) {
      $this->group->og_selective = isset($preset['og']['og_selective']) ? $preset['og']['og_selective'] : 0;
      $this->group->og_register = isset($preset['og']['og_register']) ? $preset['og']['og_register'] : 0;
      $this->group->og_directory = isset($preset['og']['og_directory']) ? $preset['og']['og_directory'] : 0;
      $this->group->og_private = isset($preset['og']['og_private']) ? $preset['og']['og_private'] : 0;
    }

    /**
     * Implementation of space->redirect().
     */
    function redirect($op = 'home') {
      switch ($op) {
        case 'home':
          if ($this->prefix) {

            // use the menu path of the selected feature as homepage
            if ($home = $this->settings['home']) {
              $features = spaces_features();
              if (is_array($features[$home]->spaces['menu'])) {
                $home_path = key($features[$home]->spaces['menu']);
                context_prefix_goto('spaces_og', $this->sid, $home_path);
              }
            }
            else {
              if (user_access('administer group features')) {
                drupal_set_message(t("Please setup your group by enabling at least 1 feature and choosing a homepage setting."));
                context_prefix_goto('spaces_og', $this->sid, 'spaces/features');
              }
            }
          }
          else {
            drupal_goto('node/' . $this->sid . '/edit');
          }
          drupal_not_found();
          exit;
          break;
      }
    }

    /**
     * Implementation of space->router().
     */
    function router($op, $object = NULL, $is_active = TRUE) {
      switch ($op) {
        case 'menu':

          // Group space is active
          if ($is_active) {
            global $user;

            // Allow access
            // Group is public
            if ($this->group->og_private != 1) {
              return drupal_is_front_page() ? $this
                ->redirect('home') : true;
            }
            else {
              if (spaces_og_is_member($gid)) {
                return drupal_is_front_page() ? $this
                  ->redirect('home') : true;
              }
              else {
                if (!$user->uid) {

                  // Give anon users access to login pages.
                  if (arg(0) == 'user' || arg(0) == 'openid') {
                    return true;
                  }
                  drupal_goto('user/login');
                }
              }
            }

            // Deny all other access
            return false;
          }
          else {
            return true;
          }
        case 'node view':
          $node = $object;

          // Omitted node
          if (og_is_omitted_type($node->type)) {
            return true;
          }
          else {
            if (og_is_group_type($node->type)) {
              $space = spaces_load('og', $node->nid);
              $space
                ->redirect('home');
            }
            else {
              if (is_array($node->og_groups) && isset($node->og_groups[0])) {
                $node_types = spaces_content_types();

                // If node type is in the feature list, check for private/public settings.
                if (isset($node_types[$node->type])) {
                  if ($is_active) {

                    // Space and node groups match, allow access
                    if (in_array($this->sid, $node->og_groups)) {
                      return true;
                    }
                    else {
                      context_prefix_goto('spaces_og', $node->og_groups[0], $_GET['q']);
                    }
                  }
                  else {

                    // Only allow group enabled nodes to be shown out of
                    // their group context if another space type is active
                    $space = spaces_get_space();
                    if ($space && $space->type != 'og') {
                      return true;
                    }
                    else {
                      context_prefix_goto('spaces_og', $node->og_groups[0], $_GET['q']);
                    }
                  }
                }
              }
              elseif (user_access('administer nodes')) {
                drupal_set_message(t('This content is not assigned to a group and it not visible to non-administrative users.'));
                return true;
              }
            }
          }
          return false;
        case 'node form':
          $node = $object;

          // Omitted node
          if (og_is_omitted_type($node->type)) {
            return true;
          }
          else {
            if (og_is_group_type($node->type)) {

              // Viewing the current space group node
              if ($is_active && $node->nid == $this->sid) {
                return true;
              }

              // Otherwise, route accordingly
              $space = spaces_load('og', $node->nid, true);
              if ($space->prefix) {
                context_prefix_goto('spaces_og', $space->sid, $_GET['q']);
              }
              else {

                // @TODO: replace this with a context_prefix_goto() that drops all prefixes...
                return true;
              }
            }
          }

          // OG-enabled nodes
          if ($is_active) {
            $node_types = spaces_content_types();
            $feature = $node_types[$node->type];
            if ($this
              ->feature_access($feature)) {
              $test_user = spaces_og_is_member($this->sid);
              $test_node = in_array($this->sid, $node->og_groups);

              // User and node are both members of current space
              if ($test_user && $test_node) {
                return true;
              }
              else {
                if (!$test_node) {
                  $gid = $node->og_groups[0];
                  if (spaces_og_is_member($gid) && ($space = spaces_load('og', $gid))) {
                    if ($dest = $_REQUEST['destination']) {
                      unset($_REQUEST['destination']);
                    }
                    context_prefix_goto('spaces_og', $space->sid, $_GET['q'], $dest ? "destinaton={$dest}" : NULL);
                  }
                }
              }
            }
          }
          elseif (user_access('administer nodes')) {
            drupal_set_message(t('This form should only be submitted within a properly configured group. Continue at your own risk.'));
            return true;
          }
          return false;
        case 'user view':
          global $user;
          $account = $object;
          if (user_access('view users outside groups') || $user->uid == $account->uid) {
            return true;
          }
          else {
            if ($is_active) {
              $test_user = spaces_og_is_member($this->sid);
              $test_account = isset($account->og_groups[$this->sid]);

              // Both user and account belong to current space
              if ($test_user && $test_account) {
                return true;
              }
              else {
                if (!$test_account) {
                  $gid = key($test_account->og_groups);
                  if (spaces_og_is_member($gid) && ($space = spaces_load('og', $gid))) {
                    context_prefix_goto('spaces_og', $space->sid, $_GET['q']);
                  }
                }
              }
            }
          }
          return false;
      }
    }

    // Spaces OG views filter
    function views_filter($is_active, &$query) {
      og_handler_filter_picg('handler', array(), array(), $query);
    }

  }
}

/**
 * Implementation of hook_init();
 */
function spaces_og_init() {
  global $conf;
  $conf['og_visibility_directory'] = 2;

  // Default to 'visible'.
  $conf['og_visibility_registration'] = 3;

  // Default to 'visible' on form.
  $conf['og_private_groups'] = 3;

  // Default group to 'public'.
  $conf['og_notification'] = 0;

  // Disable OG's Notifications.
  $conf['og_audience_checkboxes'] = 0;

  // Disable audience checkboxes.
  $conf['og_visibility'] = 2;

  // Default visibility to 'public'.
  $conf['og_audience_required'] = 1;

  // Require audience.
  $conf['og_member_pics'] = 0;

  // Disable pictures.
}

/**
 * Implementation of hook_spaces_types().
 */
function spaces_og_spaces_types() {
  return array(
    'og' => array(
      'class' => 'space_og',
      'title' => t('Group space'),
      'custom prefixes' => TRUE,
    ),
  );
}

/**
 * Implementatoin of hook_spaces_presets().
 */
function spaces_og_spaces_presets() {
  $items = array();
  $items['private'] = array(
    'type' => 'og',
    'name' => t('Private group'),
    'description' => t('Only members will be able to access this group. Membership is strictly managed by admins.'),
    'preset' => array(
      'og' => array(
        'og_selective' => OG_CLOSED,
        'og_directory' => OG_DIRECTORY_NEVER,
        'og_register' => OG_REGISTRATION_ALWAYS,
        'og_private' => defined(OG_PRIVATE_GROUPS_ALWAYS) ? OG_PRIVATE_GROUPS_ALWAYS : 1,
      ),
    ),
  );
  $items['controlled'] = array(
    'type' => 'og',
    'name' => t('Controlled group'),
    'description' => t('All users may view public content from this group. Users must request to join this group.'),
    'preset' => array(
      'og' => array(
        'og_selective' => OG_MODERATED,
        'og_directory' => OG_DIRECTORY_ALWAYS,
        'og_register' => OG_REGISTRATION_ALWAYS,
        'og_private' => defined(OG_PRIVATE_GROUPS_NEVER) ? OG_PRIVATE_GROUPS_NEVER : 0,
      ),
    ),
  );
  $items['public'] = array(
    'type' => 'og',
    'name' => t('Public group'),
    'description' => t('All users may view public content from this group. User may join this group at will.'),
    'preset' => array(
      'og' => array(
        'og_selective' => OG_OPEN,
        'og_directory' => OG_DIRECTORY_ALWAYS,
        'og_register' => OG_REGISTRATION_ALWAYS,
        'og_private' => defined(OG_PRIVATE_GROUPS_NEVER) ? OG_PRIVATE_GROUPS_NEVER : 0,
      ),
    ),
  );
  return $items;
}

/**
 * Implementation of hook_menu().
 */
function spaces_og_menu($may_cache) {
  $items = array();
  if ($may_cache) {
    $items[] = array(
      'path' => "member-list",
      'callback' => 'spaces_og_wrapper',
      'callback arguments' => array(
        'member-list',
      ),
      'title' => t('Members'),
      'type' => MENU_CALLBACK,
      'access' => user_access('administer organic groups') || og_is_node_admin($group),
    );
    $items[] = array(
      'path' => "member-add",
      'callback' => 'spaces_og_wrapper',
      'callback arguments' => array(
        'member-add',
      ),
      'title' => t('Add Members'),
      'type' => MENU_CALLBACK,
      'access' => user_access('administer organic groups') || og_is_node_admin($group),
    );
  }
  else {
    if (arg(0) == 'node' && is_numeric(arg(1)) && ($node = node_load(arg(1)))) {
      if (og_is_group_type($node->type) && ($space = spaces_get_space())) {
        $spaces_items = spaces_active_space_menu($space, true, 'node/' . arg(1));
        unset($spaces_items['spaces/settings']);
        $items = $items + $spaces_items;
      }
    }
  }
  return $items;
}

/**
 * Implementation of hook_perm().
 */
function spaces_og_perm() {
  return array(
    'administer group features',
    'view users outside groups',
  );
}

/**
 * Implementation of hook_user().
 */
function spaces_og_user($op, &$edit, &$account, $category = NULL) {
  switch ($op) {
    case 'form':
      if ($category == 'account') {

        // Add the groups selector to the user form.
        $form = og_user('register', $edit, $account, $category = NULL);
        $form['og_register']['#weight'] = 5;
        $form['og_register']['og_register']['#default_value'] = array_keys($account->og_groups);
        return $form;
      }
      break;
    case 'update':
      if (is_array($edit['og_register'])) {

        // Process groups selections.
        $active_groups = array_keys(array_filter($edit['og_register']));
        foreach (array_diff($active_groups, array_keys($account->og_groups)) as $gid) {
          $return = og_subscribe_user($gid, $account);
          if (!empty($return['message'])) {
            drupal_set_message($return['message']);
          }
        }
        foreach (array_diff(array_keys($edit['og_register']), $active_groups) as $gid) {
          og_delete_subscription($gid, $account->uid);
        }
      }
      break;
  }
}

/**
 * Implementation of hook_nodeapi().
 */
function spaces_og_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
  switch ($op) {
    case 'prepare':
      if (og_is_group_type($node->type) && ($space = spaces_load('og', $node->nid))) {
        $node->space_prefix = $space->prefix;
      }
      else {
        if ($space = spaces_get_space()) {
          _spaces_enforce_feature($space->sid, $node);
        }
      }
      break;
    case 'submit':

      // switch node's group if specified
      if (!og_is_omitted_type($node->type)) {
        if (isset($node->spaces_og['gid']) && !in_array($node->spaces_og['gid'], $node->og_groups)) {
          $new_gid = $node->spaces_og['gid'];
          _spaces_enforce_feature($new_gid, $node);
        }
      }
      break;
    case 'insert':
    case 'update':

      // save prefix & preset from node form information
      if (og_is_group_type($node->type) && isset($node->context_prefix['prefix'])) {
        $space = spaces_load('og', $node->nid);
        $space->prefix = $node->context_prefix['prefix'];
        $space->preset = $node->preset;

        // Save that shiz
        $space->save_once = TRUE;

        // Custom flag that kills node_save() recursion
        spaces_save($space);
      }
      break;
    case 'delete':
      if (og_is_group_type($node->type)) {
        $space = spaces_load('og', $node->nid);
        if ($space) {
          spaces_delete($space);
        }
      }
      break;
  }
}

/*
 * Implementation of hook_form_alter()
 */
function spaces_og_form_alter($form_id, &$form) {
  switch ($form_id) {
    default:
      if ($form['#id'] == 'node-form' && arg(0) . '/' . arg(1) != 'admin/content') {

        // GROUP NODES
        if (og_is_group_type($form['#node']->type)) {
          _spaces_og_form_alter_group($form);
        }
        elseif (!og_is_omitted_type($form['#node']->type)) {
          _spaces_og_form_alter_node($form);
        }
      }
      break;
  }
}

/**
 * Group node form_alter()
 */
function _spaces_og_form_alter_group(&$form) {
  _spaces_og_make_hidden($form['og_selective']);
  _spaces_og_make_hidden($form['og_register']);
  _spaces_og_make_hidden($form['og_private']);
  _spaces_og_make_hidden($form['og_directory']);
  _spaces_og_make_hidden($form['themes']);

  // Add context prefix form
  $form['context_prefix'] = context_prefix_form('spaces_og', $form['#node']->nid, $form['#node']->space_prefix);

  // Add presets form
  $nid = isset($form['#node']->nid) ? $form['#node']->nid : NULL;
  $space = spaces_load('og', $nid);
  $form['spaces_preset'] = spaces_form_presets($space);

  // Add custom submit handler
  $form['#submit']['_spaces_og_group_node_form_submit'] = array();
}

/**
 * Custom submit handler for group node forms
 */
function _spaces_og_group_node_form_submit($form_id, $form_values) {

  // Prefix might have changed -- do the redirect correctly
  if (isset($form_values['nid']) && isset($form_values['context_prefix']['prefix'])) {
    $nid = $form_values['nid'];
    $prefix = $form_values['context_prefix']['prefix'];
    $space = spaces_load('og', $nid);
    if ($space) {

      // Reset prefix static cache since the prefix for this group might have been changed
      $method = variable_get('context_prefix_method_' . 'spaces_og', CONTEXT_PREFIX_PATH);
      $prefixes = context_prefix_prefixes($method, TRUE);
      $space->prefix = $prefix;
      $space
        ->redirect('home');
    }
  }
}

/**
 * Group-enabled node form_alter()
 */
function _spaces_og_form_alter_node(&$form) {
  global $user;
  $space = spaces_get_space();

  // TODO: We need to present a different UI (actually, probably we don't
  // need one at all) if spaces_announce is enabled. We need to move this
  // check into spaces_announce to protect the modularity of Spaces.
  if (!module_exists('spaces_announce')) {

    // Give admins access to all group options
    if (user_access('administer organic groups')) {
      $options = array(
        t('My groups') => array(),
        t('All groups') => array(),
      );
      $options[t('All groups')] = _spaces_og_group_options($form['#node']->type);
      foreach (og_get_subscriptions($user->uid) as $node) {
        unset($options[t('All groups')][$node['nid']]);
        $options[t('My groups')][$node['nid']] = $node['title'];
      }
      if (empty($options[t('All groups')])) {
        unset($options[t('All groups')]);
      }
      if ($options) {
        if (is_array($form['#node']->og_groups) && isset($form['#node']->og_groups[0])) {
          $default_gid = $form['#node']->og_groups[0];
        }
        else {
          if ($space) {
            $default_gid = $space->sid;
          }
          else {
            $default_gid = NULL;
          }
        }
        $form['spaces_og'] = array(
          '#type' => 'fieldset',
          '#tree' => true,
          '#title' => t('Group'),
        );
        $form['spaces_og']['gid'] = array(
          '#type' => 'select',
          '#options' => $options,
          '#default_value' => $default_gid,
          '#description' => t('Please select a group to move this post to.'),
        );
      }
    }
  }

  // Recurse into og_options hiding all of them.
  _spaces_og_make_hidden($form['og_nodeapi']);
  $form['spaces'] = array(
    '#title' => t('Privacy'),
    '#type' => 'fieldset',
    '#weight' => 100,
  );
  switch ($form['#node']->og_public) {
    case OG_VISIBLE_GROUPONLY:
      $form['spaces']['#description'] = t('A post of this type is always <strong>private</strong>. Only members of this group will see it.');
      break;
    case OG_VISIBLE_BOTH:
      $form['spaces']['#description'] = t('A post of this type is always <strong>public</strong>. All visitors will see it.');
      break;
  }
}

/**
 * Set all elements in a given form to 'value'. Using value preserves the tree and prevents
 * The element from being rendered.
 */
function _spaces_og_make_hidden(&$form) {
  if (isset($form['#type'])) {
    $form['#type'] = 'value';
    $form['#required'] = false;
  }
  if (is_array($form)) {
    foreach ($form as $key => $value) {
      if (is_array($value) && strpos($key, '#') !== 0) {
        _spaces_og_make_hidden($form[$key]);
      }
    }
  }
}

/**
 * Spaces OG wrapper
 */
function spaces_og_wrapper($op) {
  switch ($op) {
    case 'member-list':
      if ($space = spaces_get_space()) {
        if (og_is_node_admin(node_load($space->sid)) && user_access('ucreate users')) {
          $links = context_get('spaces', 'links');
          $links = $links ? $links : array();
          $links['ucreate'] = array(
            'title' => t('Member'),
            'href' => 'member-add',
          );
          context_set('spaces', 'links', $links);
        }
        return og_menu_check('og_list_users_page', $space->sid);
      }
    case 'member-add':
      if (module_exists('ucreate')) {
        $form = drupal_get_form('ucreate_user_form');
        context_set('spaces', false);
      }
      return $form;
  }
}

/**
 * Custom subscription link - use "join" instead of "subscribe" - make it shorter.
 */
function spaces_og_subscription_link() {
  global $user;
  if ($user->uid && is_array($user->og_groups) && ($space = spaces_get_space())) {
    $gid = $space->sid;
    $node = node_load($gid);

    // User is a member
    if ($user->og_groups[$gid]) {

      // Do not let managers leave the group -- TODO: figure out a
      // better workflow for these situations.
      if (!og_is_node_admin($node)) {
        return array(
          'title' => t('Leave this group'),
          'href' => "og/unsubscribe/" . $node->nid,
          'query' => 'destination=' . $_GET['q'],
        );
      }
    }
    else {
      if (db_result(db_query("SELECT count(nid) FROM {og_uid} WHERE nid = %d AND uid = %d AND is_active = 0", $gid, $user->uid))) {
        return array(
          'title' => t('Cancel request to join'),
          'href' => "og/unsubscribe/" . $node->nid,
          'query' => 'destination=' . $_GET['q'],
        );
      }
      else {
        if ($node->og_selective == OG_MODERATED) {
          return array(
            'title' => t('Request to join'),
            'href' => "og/subscribe/" . $node->nid,
            'query' => 'destination=' . $_GET['q'],
          );
        }
        elseif ($node->og_selective == OG_OPEN) {
          return array(
            'title' => t('Join this group'),
            'href' => "og/subscribe/" . $node->nid,
            'query' => 'destination=' . $_GET['q'],
          );
        }
      }
    }
  }
  return;
}

/**
 * API function that enforces OG group and privacy settings on a node.
 */
function _spaces_enforce_feature($gid, &$node) {
  $map = spaces_content_types();
  $features = spaces_features($gid);
  if ($feature = $map[$node->type]) {
    if (isset($features[$feature]) && ($privacy = $features[$feature])) {
      switch ($privacy) {
        case SPACES_OG_PRIVATE:
          $node->og_public = OG_VISIBLE_GROUPONLY;
          break;
        case SPACES_OG_PUBLIC:
          $node->og_public = OG_VISIBLE_BOTH;
          break;
      }
      $node->og_groups = array(
        $gid => $gid,
      );
    }
  }
}

/**
 * Tests for user membership in group
 */
function spaces_og_is_member($gid = null, $uid = null) {
  global $user;
  if (!$gid && ($space = spaces_get_space())) {
    $gid = $space->sid;
  }
  $account = $uid ? user_load(array(
    'uid' => $uid,
  )) : $user;
  if ($gid && $account) {
    if (user_access('administer organic groups', $account)) {
      return true;
    }
    else {
      if (is_array($account->og_groups) && $account->og_groups[$gid]) {
        return true;
      }
    }
  }
  return false;
}

/**
 * Generates an array of groups that a node could potentially
 * be a member of based on enabled spaces features and optionally
 * the specified user's groups
 */
function _spaces_og_group_options($type, $uid = 0) {
  $types = spaces_content_types();
  $group_options = array();
  $args = array(
    $types[$type],
    0,
  );
  if ($uid) {
    $join = "JOIN {og_uid} ogu ON ogu.nid = og.nid";
    $where = "AND ogu.uid = %d AND ogu.is_active >= 1";
    $args[] = $uid;
  }
  $result = db_query("SELECT og.nid, n.title\n    FROM {og}\n      JOIN {node} n ON og.nid = n.nid\n      JOIN {spaces_features} sf ON sf.sid = og.nid\n      {$join}\n    WHERE n.status = 1\n      AND sf.id = '%s'\n      AND sf.value != %d\n      {$where}\n    ORDER BY n.title ASC", $args);
  while ($group = db_fetch_object($result)) {
    $group_options[$group->nid] = $group->title;
  }
  return $group_options;
}

/**
 * Implementation of hook_requirements().
 */
function spaces_og_requirements($phase) {
  $requirements = array();
  $t = get_t();
  switch ($phase) {
    case 'runtime':

      // Check that existing node types are og enabled
      $types = spaces_content_types();
      $existing_types = node_get_types();
      foreach ($types as $type => $feature) {
        if (og_is_omitted_type($type) && array_key_exists($type, $existing_types)) {
          $requirements['spaces'] = array(
            'title' => $t('Spaces OG configuration'),
            'description' => $t('The !type content type appear to be misconfigured.', array(
              '!type' => l($type, 'admin/content/types/' . $type),
            )),
            'severity' => REQUIREMENT_ERROR,
            'value' => $t('OG Misconfiguration'),
          );
          return $requirements;
        }
      }
      $requirements['spaces'] = array(
        'title' => $t('Spaces OG configuration'),
        'description' => t('The spaces og module is installed and configured properly'),
        'severity' => REQUIREMENT_OK,
        'value' => $t('Installed correctly'),
      );
  }
  return $requirements;
}

/**
 * Get drupal users
 *
 * @param $exclude_system
 *   Bool, whether to exclude system user - ie user 1
 *
 * @return
 *   Array of user objects, where key is uid.
 */
function spaces_og_get_users($exclude_system = true, $active_only = true, $group_only = true, $pager = 0) {
  $args[] = $exclude_system ? 1 : 0;
  $args[] = $active_only ? 1 : 0;
  if ($group_only && ($space = spaces_get_space())) {
    $join = 'JOIN {og_uid} ogu ON u.uid = ogu.uid';
    $where = 'AND ogu.nid = %d';
    $args[] = $space->sid;
  }
  if ($pager == 0) {
    $result = db_query("SELECT u.uid, u.name, u.mail, u.picture, u.status FROM {users} u {$join} WHERE u.uid > %d AND u.status >= %d {$where} ORDER BY name", $args);
  }
  else {
    $result = pager_query("SELECT u.uid, u.name, u.mail, u.picture, u.status FROM {users} u {$join} WHERE u.uid > %d AND u.status >= %d {$where} ORDER BY name", $pager, 0, null, $args);
  }
  $users = array();
  while ($u = db_fetch_object($result)) {
    $users[$u->uid] = $u;
  }
  return $users;
}

/**
 * Implementation of hook_spaces_node_links_alter().
 */
function spaces_og_spaces_node_links_alter(&$links) {
  $space = spaces_get_space();

  // If we are not in an OG space, remove all node links for OG
  // enabled content types to prevent users from submitting nodes
  // outside of a group context.
  if ($space && $space->type != 'og' || !$space) {
    foreach ($links as $type => $link) {
      if (!og_is_omitted_type($type) && !og_is_group_type($type)) {
        unset($links[$type]);
      }
    }
  }
}

Functions

Namesort descending Description
spaces_og_form_alter
spaces_og_get_users Get drupal users
spaces_og_init Implementation of hook_init();
spaces_og_is_member Tests for user membership in group
spaces_og_menu Implementation of hook_menu().
spaces_og_nodeapi Implementation of hook_nodeapi().
spaces_og_perm Implementation of hook_perm().
spaces_og_requirements Implementation of hook_requirements().
spaces_og_spaces_node_links_alter Implementation of hook_spaces_node_links_alter().
spaces_og_spaces_presets Implementatoin of hook_spaces_presets().
spaces_og_spaces_types Implementation of hook_spaces_types().
spaces_og_subscription_link Custom subscription link - use "join" instead of "subscribe" - make it shorter.
spaces_og_user Implementation of hook_user().
spaces_og_wrapper Spaces OG wrapper
_spaces_enforce_feature API function that enforces OG group and privacy settings on a node.
_spaces_og_form_alter_group Group node form_alter()
_spaces_og_form_alter_node Group-enabled node form_alter()
_spaces_og_group_node_form_submit Custom submit handler for group node forms
_spaces_og_group_options Generates an array of groups that a node could potentially be a member of based on enabled spaces features and optionally the specified user's groups
_spaces_og_make_hidden Set all elements in a given form to 'value'. Using value preserves the tree and prevents The element from being rendered.

Constants