You are here

function ldap_server_massage_text in Lightweight Directory Access Protocol (LDAP) 7.2

Same name and namespace in other branches
  1. 8.2 ldap_servers/ldap_servers.functions.inc \ldap_server_massage_text()
  2. 7 ldap_servers/ldap_servers.functions.inc \ldap_server_massage_text()

Function to massage (change case, escape, unescape) ldap attribute names and values. The primary purpose of this is to articulate and ensure consistency across ldap modules.

Parameters

mixed $value: to be massaged.

string $value_type: = 'attr_name' or 'attr_value;.

enum $context: ...see LDAP_SERVER_MASSAGE_* constants

.e.g. ldap_server_massage_text($value, 'attr_value', LDAP_SERVER_MASSAGE_QUERY_LDAP)

Return value

array|mixed|string

2 calls to ldap_server_massage_text()
LdapServer::userUserNameToExistingLdapEntry in ldap_servers/LdapServer.class.php
Queries LDAP server for the user.
theme_ldap_query_results in ldap_query/ldap_query.theme.inc

File

ldap_servers/ldap_servers.functions.inc, line 165
Collection of functions that don't belong in server object.

Code

function ldap_server_massage_text($value, $value_type, $context) {
  $scalar = is_scalar($value);
  if ($value_type == 'attr_value') {
    if ($context == LDAP_SERVER_MASSAGE_QUERY_LDAP) {
      $value = ldap_pear_escape_filter_value($value);
    }
    elseif ($context == LDAP_SERVER_MASSAGE_STORE_LDAP) {
      $value = ldap_pear_escape_dn_value($value);
    }
    switch ($context) {
      case LDAP_SERVER_MASSAGE_DISPLAY:
      case LDAP_SERVER_MASSAGE_TOKEN_REPLACE:
      case LDAP_SERVER_MASSAGE_QUERY_LDAP:
      case LDAP_SERVER_MASSAGE_QUERY_DB:
      case LDAP_SERVER_MASSAGE_QUERY_ARRAY:
      case LDAP_SERVER_MASSAGE_QUERY_PROPERTY:
      case LDAP_SERVER_MASSAGE_STORE_LDAP:
      case LDAP_SERVER_MASSAGE_STORE_DB:
      case LDAP_SERVER_MASSAGE_STORE_ARRAY:
      case LDAP_SERVER_MASSAGE_STORE_PROPERTY:
        break;
    }
  }
  elseif ($value_type == 'attr_name') {
    switch ($context) {
      case LDAP_SERVER_MASSAGE_DISPLAY:
        break;
      case LDAP_SERVER_MASSAGE_TOKEN_REPLACE:
      case LDAP_SERVER_MASSAGE_QUERY_LDAP:
      case LDAP_SERVER_MASSAGE_QUERY_DB:
      case LDAP_SERVER_MASSAGE_QUERY_ARRAY:
      case LDAP_SERVER_MASSAGE_QUERY_PROPERTY:
      case LDAP_SERVER_MASSAGE_STORE_LDAP:
      case LDAP_SERVER_MASSAGE_STORE_DB:
      case LDAP_SERVER_MASSAGE_STORE_ARRAY:
      case LDAP_SERVER_MASSAGE_STORE_PROPERTY:
        if ($scalar) {
          $value = drupal_strtolower($value);
        }
        elseif (is_array($value)) {
          foreach ($value as $i => $val) {
            $value[$i] = drupal_strtolower($val);
          }
        }
        else {

          // Neither scalar nor array $value.
        }
        break;
    }
  }
  return $value;
}