You are here

function simple_ldap_user_variable_get in Simple LDAP 7.2

Same name and namespace in other branches
  1. 7 simple_ldap_user/simple_ldap_user.module \simple_ldap_user_variable_get()

Returns the value for the specified variable.

This function takes into account the configured LDAP server type, and attempts to determine a reasonable default value to try to use in the event that the module has not yet been configured.

45 calls to simple_ldap_user_variable_get()
SimpleLdapRole::addUser in simple_ldap_role/SimpleLdapRole.class.php
Add an LDAP user to the LDAP group.
SimpleLdapRole::deleteUser in simple_ldap_role/SimpleLdapRole.class.php
Remove an LDAP user from the LDAP group.
SimpleLdapRoleChangeDrupalUserRoleTestCase::testChangeDrupalUserRole in simple_ldap_role/simple_ldap_role.test
Changes a user's drupal roles.
SimpleLdapRoleChangeLdapGroupMembership::testChangeLdapGroupMembership in simple_ldap_role/simple_ldap_role.test
Test changing group membership directly in LDAP.
SimpleLdapUser::fetch_puid in simple_ldap_user/SimpleLdapUser.class.php
Special function to fetch the PUID of a record.

... See full list

File

simple_ldap_user/simple_ldap_user.module, line 1311
Main simple_ldap_user module file.

Code

function simple_ldap_user_variable_get($name, $default = NULL, $force_default = FALSE) {

  // Cache certain variables
  static $cache = array();

  // Allow variable name shorthand by prepending 'simple_ldap_user_' to $name if
  // it is not already there.
  if (strpos($name, 'simple_ldap_user_') !== 0) {
    $name = 'simple_ldap_user_' . $name;
  }

  // Returned cached value if present
  if (array_key_exists($name, $cache)) {
    return $cache[$name];
  }

  // Get an LDAP server object.
  $server = SimpleLdapServer::singleton();

  // Handle special variables.
  switch ($name) {
    case 'simple_ldap_user_source':

      // If the LDAP server is set to read-only, force LDAP->Drupal sync.
      if ($server->readonly) {
        return 'ldap';
      }
      break;
    case 'simple_ldap_user_attribute_map':

      // Load the attribute map from settings.php.
      $attribute_map = variable_get($name, array());

      // LDAP likes lowercase.
      array_change_key_case($attribute_map, CASE_LOWER);
      foreach ($attribute_map as $key => $value) {

        // Make sure the Drupal attribute is an array.
        if (!is_array($attribute_map[$key])) {
          $attribute_map[$key] = array(
            $value,
          );
        }
      }
      $cache[$name] = $attribute_map;
      return $attribute_map;
  }

  // Define defaults that differ based on LDAP server type.
  switch ($server->type) {
    case 'Active Directory':
      $defaults = array(
        'simple_ldap_user_objectclass' => 'user',
        'simple_ldap_user_attribute_name' => 'samaccountname',
        'simple_ldap_user_attribute_mail' => 'mail',
        'simple_ldap_user_attribute_pass' => 'unicodepwd',
        'simple_ldap_user_password_hash' => 'unicode',
        'simple_ldap_user_attribute_rdn' => 'cn',
      );
      break;
    default:
      $defaults = array(
        'simple_ldap_user_objectclass' => 'inetorgperson',
        'simple_ldap_user_attribute_name' => 'cn',
        'simple_ldap_user_attribute_mail' => 'mail',
        'simple_ldap_user_attribute_pass' => 'userpassword',
        'simple_ldap_user_password_hash' => 'salted sha',
      );
  }

  // Define defaults that do not depend on LDAP server type.
  $defaults['simple_ldap_user_auxiliaryclasses'] = array();
  $defaults['simple_ldap_user_basedn'] = $server->basedn;
  $defaults['simple_ldap_user_scope'] = 'sub';
  $defaults['simple_ldap_user_source'] = 'ldap';
  $defaults['simple_ldap_user_sync'] = 'hook_user_load';
  $defaults['simple_ldap_user_delete_from_ldap'] = '1';
  $defaults['simple_ldap_user_auth_fallback'] = array();
  $defaults['simple_ldap_user_auth_fallback_writeback'] = array();
  $defaults['simple_ldap_user_extra_attrs'] = array();
  $defaults['simple_ldap_user_unique_attribute'] = '';

  // Determine the default value for the given variable.
  $default = isset($defaults[$name]) ? $defaults[$name] : $default;
  if ($force_default) {
    return $default;
  }
  return variable_get($name, $default);
}