View source
<?php
function ldap_feeds_feeds_plugins() {
$path = drupal_get_path('module', 'ldap_feeds');
$info = array();
$info['FeedsLdapQueryFetcher'] = array(
'name' => 'LDAP Query Fetcher',
'description' => 'Fetch content from ldap query',
'handler' => array(
'parent' => 'FeedsFetcher',
'class' => 'FeedsLdapQueryFetcher',
'file' => 'FeedsLdapQueryFetcher.inc',
'path' => $path,
),
);
$info['FeedsDrupalUserLdapEntryFetcher'] = array(
'name' => 'Drupal User LDAP Entry Fetcher',
'description' => 'Fetches one entry for each LDAP authenticated user. Fetches both LDAP entry attributes such as
<code>cn, dn,</code> etc.
and Drupal user data such as <code>uid, name, mail, created, status, language, </code>and <code>signature</code>.',
'handler' => array(
'parent' => 'FeedsFetcher',
'class' => 'FeedsDrupalUserLdapEntryFetcher',
'file' => 'FeedsDrupalUserLdapEntryFetcher.inc',
'path' => $path,
),
);
$info['FeedsLdapEntryParser'] = array(
'name' => t('LDAP Entry Parser for Feeds'),
'description' => t('Parse an LDAP Entry Array'),
'handler' => array(
'parent' => 'FeedsParser',
'class' => 'FeedsLdapEntryParser',
'file' => 'FeedsLdapEntryParser.inc',
'path' => $path,
),
);
return $info;
}
function ldap_feeds_enable() {
cache_clear_all('plugins:feeds:plugins', 'cache');
}
function ldap_feeds_drupal_user_attributes() {
$attributes = array(
'uid' => array(
'token' => 'drupal.uid',
'description' => 'Drupal used id. e.g. 413',
),
'name' => array(
'token' => 'drupal.name',
'description' => 'Drupal username. e.g. jdoe',
),
'mail' => array(
'token' => 'drupal.mail',
'description' => 'Drupal email address. e.g. jdoe@gmail.com',
),
'created' => array(
'token' => 'drupal.created',
'description' => 'Drupal account created timestamp in unix e.g. 432432432',
),
'status' => array(
'token' => 'drupal.status',
'description' => 'Drupal user status e.g. 1 or 0',
),
'language' => array(
'token' => 'drupal.language',
'description' => 'Drupal language.',
),
'signature' => array(
'token' => 'drupal.signature',
'description' => 'Drupal signature. e.g. Happy Joe',
),
'login' => array(
'token' => 'drupal.login',
'description' => 'Drupal unix timestamp of last login e.g. 1317494439',
),
'init' => array(
'token' => 'drupal.init',
'description' => 'Drupal user init e.g. jdoe@gmail.com',
),
);
drupal_alter('ldap_feeds_drupal_user_attributes', $attributes);
return $attributes;
}
function ldap_feeds_form_feeds_ui_mapping_form_alter(&$form, &$form_state, $form_id) {
if (@$form['#importer']->config['fetcher']['plugin_key'] == 'FeedsDrupalUserLdapEntryFetcher') {
ldap_feeds_drupal_user_legend($form);
}
elseif (@$form['#importer']->config['fetcher']['plugin_key'] == 'FeedsLdapQueryFetcher') {
ldap_feeds_query_legend($form);
}
}
function ldap_feeds_query_legend(&$form) {
}
function _ldap_feeds_query_legend($records, $field_name) {
$examples = array();
foreach ($records as $i => $record) {
$examples[] = $record[$field_name];
if ($i > 5) {
break;
}
}
return join(', ', array_filter($examples));
}
function ldap_feeds_drupal_user_legend(&$form) {
$sources = array();
$servers = ldap_servers_get_servers(NULL, 'enabled');
$form['legendset']['#description'] = "";
$drupal_user_attributes = $form['#importer']->config['fetcher']['config']['availableDrupalUserAttributes'];
foreach ($drupal_user_attributes as $attr_name => $attr_conf) {
$id = $attr_conf['token'];
$sources[$id] = array(
'name' => array(
'#markup' => $id,
),
'description' => array(
'#markup' => '',
),
);
}
foreach ($servers as $sid => $ldap_server) {
if ($ldap_server->testingDrupalUsername) {
$account = user_load_by_name($ldap_server->testingDrupalUsername);
foreach ($drupal_user_attributes as $attr_name => $attr_conf) {
$id = $attr_conf['token'];
if ($account) {
$sources[$id] = array(
'name' => array(
'#markup' => $id,
),
'description' => array(
'#markup' => $account->{$attr_name},
),
);
}
}
$user_ldap_entry = ldap_servers_get_user_ldap_data($ldap_server->testingDrupalUsername, $sid);
foreach ($user_ldap_entry['attr'] as $id => $value) {
if (!is_numeric($id) && is_scalar($user_ldap_entry['attr'][$id][0]) && $user_ldap_entry['attr'][$id]['count'] == 1) {
$sources[$id] = array(
'name' => array(
'#markup' => $id,
),
'description' => array(
'#markup' => $user_ldap_entry['attr'][$id][0],
),
);
}
elseif ($user_ldap_entry['attr'][$id]['count'] > 1) {
$item = t('MULTIVALUED ATTRIBUTE:') . join(" , \n", $user_ldap_entry['attr'][$id]);
$sources[$id] = array(
'name' => array(
'#markup' => $id,
),
'description' => array(
'#markup' => $item,
),
);
}
}
$form['legendset']['#description'] .= t('LDAP Attributes in the source "description" column are from testing ldap user (%testing_user) on the server %sid, which is configured in
the ldap server form.', array(
'%sid' => $sid,
'%testing_user' => $ldap_server->testingDrupalUsername,
));
}
else {
foreach (array(
'dn' => 'distinguished name',
'cn' => 'cname',
) as $id => $value) {
$sources[$id] = array(
'name' => array(
'#markup' => $id,
),
'description' => array(
'#markup' => $value,
),
);
}
}
}
$form['legendset']['legend']['sources'] = $sources;
}