1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* Implements hook_ctools_plugin_api().
|
5 |
|
|
*/
|
6 |
|
|
function ldap_feeds_ctools_plugin_api($owner, $api) {
|
7 |
|
|
if ($owner == 'feeds' && $api == 'plugins') {
|
8 |
|
|
return array('version' => 1);
|
9 |
|
|
}
|
10 |
|
|
}
|
11 |
|
|
|
12 |
|
|
/**
|
13 |
|
|
* Implements hook_feeds_plugins().
|
14 |
|
|
*/
|
15 |
|
|
function ldap_feeds_feeds_plugins() {
|
16 |
|
|
|
17 |
|
|
$path = drupal_get_path('module', 'ldap_feeds');
|
18 |
|
|
$info = array();
|
19 |
|
|
|
20 |
|
|
$info['FeedsLdapQueryFetcher'] = array(
|
21 |
|
|
'name' => 'LDAP Query Fetcher',
|
22 |
|
|
'description' => 'Fetch content from ldap query',
|
23 |
|
|
'handler' => array(
|
24 |
|
|
'parent' => 'FeedsFetcher', // This is the key name, not the class name.
|
25 |
|
|
'class' => 'FeedsLdapQueryFetcher',
|
26 |
|
|
'file' => 'FeedsLdapQueryFetcher.inc',
|
27 |
|
|
'path' => $path,
|
28 |
|
|
),
|
29 |
|
|
);
|
30 |
|
|
|
31 |
|
|
$info['FeedsDrupalUserLdapEntryFetcher'] = array(
|
32 |
|
|
'name' => 'Drupal User LDAP Entry Fetcher',
|
33 |
|
|
'description' => 'Fetches one entry for each LDAP authenticated user. Fetches both LDAP entry attributes such as
|
34 |
|
|
<code>cn, dn,</code> etc.
|
35 |
|
|
and Drupal user data such as <code>uid, name, mail, created, status, language, </code>and <code>signature</code>.',
|
36 |
|
|
'handler' => array(
|
37 |
|
|
'parent' => 'FeedsFetcher', // This is the key name, not the class name.
|
38 |
|
|
'class' => 'FeedsDrupalUserLdapEntryFetcher',
|
39 |
|
|
'file' => 'FeedsDrupalUserLdapEntryFetcher.inc',
|
40 |
|
|
'path' => $path,
|
41 |
|
|
),
|
42 |
|
|
);
|
43 |
|
|
|
44 |
|
|
$info['FeedsLdapEntryParser'] = array(
|
45 |
|
|
'name' => t('LDAP Entry Parser for Feeds'),
|
46 |
|
|
'description' => t('Parse an LDAP Entry Array'),
|
47 |
|
|
'handler' => array(
|
48 |
|
|
'parent' => 'FeedsParser',
|
49 |
|
|
'class' => 'FeedsLdapEntryParser',
|
50 |
|
|
'file' => 'FeedsLdapEntryParser.inc',
|
51 |
|
|
'path' => $path,
|
52 |
|
|
),
|
53 |
|
|
);
|
54 |
|
|
|
55 |
|
|
return $info;
|
56 |
|
|
|
57 |
|
|
}
|
58 |
|
|
|
59 |
|
|
/**
|
60 |
|
|
* Implements hook_enable().
|
61 |
|
|
*
|
62 |
|
|
* Clear Feed's plugin cache so that this plugin shows up.
|
63 |
|
|
*/
|
64 |
|
|
function ldap_feeds_enable() {
|
65 |
|
|
cache_clear_all('plugins:feeds:plugins', 'cache');
|
66 |
|
|
}
|
67 |
|
|
|
68 |
|
|
function ldap_feeds_drupal_user_attributes() {
|
69 |
|
|
|
70 |
|
|
$attributes = array(
|
71 |
|
|
'uid' => array('token' => 'drupal.uid', 'description' => 'Drupal used id. e.g. 413'),
|
72 |
|
|
'name' => array('token' => 'drupal.name', 'description' => 'Drupal username. e.g. jdoe'),
|
73 |
|
|
'mail' => array('token' => 'drupal.mail', 'description' => 'Drupal email address. e.g. jdoe@gmail.com'),
|
74 |
|
|
'created' => array('token' => 'drupal.created', 'description' => 'Drupal account created timestamp in unix e.g. 432432432'),
|
75 |
|
|
'status' => array('token' => 'drupal.status', 'description' => 'Drupal user status e.g. 1 or 0'),
|
76 |
|
|
'language' => array('token' => 'drupal.language', 'description' => 'Drupal language.'),
|
77 |
|
|
'signature' => array('token' => 'drupal.signature', 'description' => 'Drupal signature. e.g. Happy Joe'),
|
78 |
|
|
'login' => array('token' => 'drupal.login', 'description' => 'Drupal unix timestamp of last login e.g. 1317494439'),
|
79 |
|
|
'init' => array('token' => 'drupal.init', 'description' => 'Drupal user init e.g. jdoe@gmail.com'),
|
80 |
|
|
);
|
81 |
|
|
// ldap_authentication and some other modules may want to add additional drupal user tokens
|
82 |
|
|
// largely derived from the $user->data array, but possibly from related data such as authmaps
|
83 |
|
|
// some use cases for alter are simply edge cases
|
84 |
|
|
|
85 |
|
|
drupal_alter('ldap_feeds_drupal_user_attributes', $attributes);
|
86 |
|
|
|
87 |
|
|
return $attributes;
|
88 |
|
|
}
|
89 |
|
|
|
90 |
|
|
/**
|
91 |
|
|
* show some sample ldap user data to help with mapping interface
|
92 |
|
|
*/
|
93 |
|
|
|
94 |
|
|
function ldap_feeds_form_feeds_ui_mapping_form_alter(&$form, &$form_state, $form_id) {
|
95 |
|
|
|
96 |
|
|
$importer = feeds_importer_load($form['#importer']);
|
97 |
|
|
|
98 |
|
|
if ($importer->config['fetcher']['plugin_key'] == 'FeedsDrupalUserLdapEntryFetcher') {
|
99 |
|
|
ldap_feeds_drupal_user_legend($form, $importer);
|
100 |
|
|
}
|
101 |
|
|
elseif ($importer->config['fetcher']['plugin_key'] == 'FeedsLdapQueryFetcher') {
|
102 |
|
|
ldap_feeds_query_legend($form, $importer);
|
103 |
|
|
}
|
104 |
|
|
}
|
105 |
|
|
|
106 |
|
|
/**
|
107 |
|
|
* add additional data to mapping form for ldap query fetcher
|
108 |
|
|
*/
|
109 |
|
|
function ldap_feeds_query_legend(&$form, $importer) {
|
110 |
|
|
|
111 |
|
|
$source = feeds_source($importer->id);
|
112 |
|
|
$fetcher = feeds_plugin('FeedsLdapQueryFetcher', $source->importer->id);
|
113 |
|
|
//dpm((array)$fetcher); dpm((array)$source->importer->parser->ldap_result);
|
114 |
|
|
// $fetcher_result = new FeedsLdapQueryFetcher($source->config);
|
115 |
|
|
// $records = $fetcher->getRaw(); // FeedsSource $source
|
116 |
|
|
// dpm($records);
|
117 |
|
|
// foreach ($records[0] as $field_name => $value) {
|
118 |
|
|
// $sources[$field_name] = array(
|
119 |
|
|
// 'name' => array('#markup' => $field_name),
|
120 |
|
|
// 'description' => array('#markup' => _ldap_feeds_query_legend($records, $field_name)));
|
121 |
|
|
// }
|
122 |
|
|
// $form['legendset']['#description'] = t('Name column is the value that should go in the SOURCE column above. Description column are from first few records of query in fetcher.', $tokens);
|
123 |
|
|
// $form['legendset']['legend']['sources'] = $sources;
|
124 |
|
|
|
125 |
|
|
}
|
126 |
|
|
|
127 |
|
|
function _ldap_feeds_query_legend($records, $field_name) {
|
128 |
|
|
$examples = array();
|
129 |
|
|
foreach ($records as $i => $record) {
|
130 |
|
|
$examples[] = $record[$field_name];
|
131 |
|
|
if ($i > 5 ) {
|
132 |
|
|
break;
|
133 |
|
|
}
|
134 |
|
|
}
|
135 |
|
|
return join(', ', array_filter($examples));
|
136 |
|
|
}
|
137 |
|
|
/**
|
138 |
|
|
* add additional data to mapping form for drupal user fetcher
|
139 |
|
|
*/
|
140 |
|
|
function ldap_feeds_drupal_user_legend(&$form, $importer) {
|
141 |
|
|
|
142 |
|
|
$sources = array();
|
143 |
|
|
$servers = ldap_servers_get_servers(NULL, 'enabled');
|
144 |
|
|
$form['legendset']['#description'] = "";
|
145 |
|
|
$drupal_user_attributes = $importer->config['fetcher']['config']['availableDrupalUserAttributes'];
|
146 |
|
|
|
147 |
|
|
foreach ($drupal_user_attributes as $attr_name => $attr_conf) {
|
148 |
|
|
$id = $attr_conf['token'];
|
149 |
|
|
$sources[$id] = array('name' => array('#markup' => $id), 'description' => array('#markup' => ''));
|
150 |
|
|
}
|
151 |
|
|
|
152 |
|
|
foreach ($servers as $sid => $ldap_server) {
|
153 |
|
|
if ($ldap_server->testingDrupalUsername) {
|
154 |
|
|
$account = user_load_by_name($ldap_server->testingDrupalUsername);
|
155 |
|
|
|
156 |
|
|
foreach ($drupal_user_attributes as $attr_name => $attr_conf) {
|
157 |
|
|
if ($attr_name == 'count') {
|
158 |
|
|
continue;
|
159 |
|
|
}
|
160 |
|
|
$id = $attr_conf['token'];
|
161 |
|
|
if ($account) {
|
162 |
|
|
$sources[$id] = array('name' => array('#markup' => $id), 'description' => array('#markup' => $account->{$attr_name}));
|
163 |
|
|
}
|
164 |
|
|
}
|
165 |
|
|
|
166 |
|
|
$ldap_user = ldap_servers_get_user_ldap_data($ldap_server->testingDrupalUsername, $sid);
|
167 |
|
|
foreach ($ldap_user['attr'] as $id => $value) {
|
168 |
|
|
if (!is_numeric($id) && is_scalar($ldap_user['attr'][$id][0]) && $ldap_user['attr'][$id]['count'] == 1) {
|
169 |
|
|
$sources[$id] = array('name' => array('#markup' => $id), 'description' => array('#markup' => $ldap_user['attr'][$id][0]));
|
170 |
|
|
}
|
171 |
|
|
elseif ($ldap_user['attr'][$id]['count'] > 1) {
|
172 |
|
|
$item = t('MULTIVALUED ATTRIBUTE:') . join(" , \n", $ldap_user['attr'][$id]);
|
173 |
|
|
$sources[$id] = array('name' => array('#markup' => $id), 'description' => array('#markup' => $item));
|
174 |
|
|
}
|
175 |
|
|
}
|
176 |
|
|
$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
|
177 |
|
|
the ldap server form.', array('%sid' => $sid, '%testing_user' => $ldap_server->testingDrupalUsername));
|
178 |
|
|
}
|
179 |
|
|
else {
|
180 |
|
|
foreach (array('dn' => 'distinguished name', 'cn' => 'cname') as $id => $value) {
|
181 |
|
|
$sources[$id] = array('name' => array('#markup' => $id), 'description' => array('#markup' => $value));
|
182 |
|
|
}
|
183 |
|
|
}
|
184 |
|
|
}
|
185 |
|
|
$form['legendset']['legend']['sources'] = $sources;
|
186 |
|
|
|
187 |
|
|
} |