You are here

function simple_ldap_user_translate_url_ldap_to_drupal in Simple LDAP 7.2

1 string reference to 'simple_ldap_user_translate_url_ldap_to_drupal'
simple_ldap_user_simple_ldap_data_handlers in simple_ldap_user/simple_ldap_user.module
Implements HOOK_simple_ldap_data_handlers()

File

simple_ldap_user/simple_ldap_user.ldap_handlers.inc, line 207

Code

function simple_ldap_user_translate_url_ldap_to_drupal(&$edit, $info, $items, $ldap_attr, $language) {

  // Synchronize types that go in ['value'] and are strings
  $dirty = FALSE;
  for ($i = 0; $i < $ldap_attr['count']; $i++) {
    if ($i < $info['cardinality'] || $info['cardinality'] == FIELD_CARDINALITY_UNLIMITED) {
      $new_url = array();
      $new_url['attributes'] = array();
      preg_match('/(<a.*href="(.*?)".*>(.*)<\\/a>|(.*))/', $ldap_attr[$i], $matches);
      if (!empty($matches[4])) {
        $new_url['value'] = $matches[4];
        $new_url['title'] = '';
      }
      else {
        $new_url['title'] = $matches[3];
        $new_url['value'] = $matches[2];
      }

      // Still save it in edit, in case only one of the set changed.
      $edit[$info['field_name']][$language][$i] = $new_url;
      if ($items[$i] != $new_url) {
        $dirty = TRUE;
      }
    }
  }

  // Check if any changes were actually made.
  if (!$dirty) {
    unset($edit[$info['field_name']]);
  }
}