You are here

function simple_ldap_role_variable_get in Simple LDAP 7.2

Same name and namespace in other branches
  1. 7 simple_ldap_role/simple_ldap_role.module \simple_ldap_role_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.

20 calls to simple_ldap_role_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.
SimpleLdapRole::filter in simple_ldap_role/SimpleLdapRole.class.php
Return the LDAP search filter, as set by the module configuration.
SimpleLdapRole::save in simple_ldap_role/SimpleLdapRole.class.php
Save role to LDAP.
SimpleLdapRole::__construct in simple_ldap_role/SimpleLdapRole.class.php
Constructor.

... See full list

File

simple_ldap_role/simple_ldap_role.module, line 329
Main simple_ldap_role module file.

Code

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

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

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

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

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

  // Define defaults that differ based on LDAP server type.
  switch ($server->type) {
    case 'Active Directory':
      $defaults = array(
        'simple_ldap_role_objectclass' => array(
          'group',
        ),
        'simple_ldap_role_attribute_name' => 'cn',
        'simple_ldap_role_attribute_member' => 'member',
        'simple_ldap_role_attribute_member_format' => 'dn',
      );
      break;
    default:
      $defaults = array(
        'simple_ldap_role_objectclass' => array(
          'groupofnames',
        ),
        'simple_ldap_role_attribute_name' => 'cn',
        'simple_ldap_role_attribute_member' => 'member',
        'simple_ldap_role_attribute_member_format' => 'dn',
      );
  }

  // Define defaults that do not depend on LDAP server type.
  $defaults['simple_ldap_role_basedn'] = $server->basedn;
  $defaults['simple_ldap_role_scope'] = 'sub';
  $defaults['simple_ldap_role_source'] = 'ldap';
  $defaults['simple_ldap_role_sync'] = 'hook_user_load';

  // 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);
}