Projet

Général

Profil

Révision 32700c57

Ajouté par Assos Assos il y a environ 5 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/ldap/ldap_feeds/ldap_feeds.module
9 9
 */
10 10
function ldap_feeds_ctools_plugin_api($owner, $api) {
11 11
  if ($owner == 'feeds' && $api == 'plugins') {
12
  return array('version' => 1);
12
    return ['version' => 1];
13 13
  }
14 14
}
15 15

  
......
19 19
function ldap_feeds_feeds_plugins() {
20 20

  
21 21
  $path = drupal_get_path('module', 'ldap_feeds');
22
  $info = array();
22
  $info = [];
23 23

  
24
  $info['FeedsLdapQueryFetcher'] = array(
24
  $info['FeedsLdapQueryFetcher'] = [
25 25
    'name' => 'LDAP Query Fetcher',
26 26
    'description' => 'Fetch content from ldap query',
27
    'handler' => array(
28
      'parent' => 'FeedsFetcher', // This is the key name, not the class name.
27
    'handler' => [
28
       // This is the key name, not the class name.
29
      'parent' => 'FeedsFetcher',
29 30
      'class' => 'FeedsLdapQueryFetcher',
30 31
      'file' => 'FeedsLdapQueryFetcher.inc',
31 32
      'path' => $path,
32
    ),
33
  );
33
    ],
34
  ];
34 35

  
35
  $info['FeedsDrupalUserLdapEntryFetcher'] = array(
36
  $info['FeedsDrupalUserLdapEntryFetcher'] = [
36 37
    'name' => 'Drupal User LDAP Entry Fetcher',
37 38
    'description' => 'Fetches one entry for each LDAP authenticated user.  Fetches both LDAP entry attributes such as
38 39
    <code>cn, dn,</code> etc.
39 40
      and Drupal user data such as <code>uid, name, mail, created, status, language, </code>and <code>signature</code>.
40 41
      Make sure to add dn in your LDAP query for this parser, if you use custom attributes.',
41
    'handler' => array(
42
      'parent' => 'FeedsFetcher', // This is the key name, not the class name.
42
    'handler' => [
43
      // This is the key name, not the class name.
44
      'parent' => 'FeedsFetcher',
43 45
      'class' => 'FeedsDrupalUserLdapEntryFetcher',
44 46
      'file' => 'FeedsDrupalUserLdapEntryFetcher.inc',
45 47
      'path' => $path,
46
    ),
47
  );
48
    ],
49
  ];
48 50

  
49
  $info['FeedsLdapEntryParser'] = array(
51
  $info['FeedsLdapEntryParser'] = [
50 52
    'name'        => t('LDAP Entry Parser for Feeds'),
51 53
    'description' => t('Parse an LDAP Entry Array'),
52
    'handler'     => array(
54
    'handler'     => [
53 55
      'parent' => 'FeedsParser',
54 56
      'class'  => 'FeedsLdapEntryParser',
55 57
      'file'   => 'FeedsLdapEntryParser.inc',
56 58
      'path'   => $path,
57
    ),
58
  );
59
    ],
60
  ];
59 61

  
60 62
  return $info;
61 63

  
......
70 72
  cache_clear_all('plugins:feeds:plugins', 'cache');
71 73
}
72 74

  
75
/**
76
 *
77
 */
73 78
function ldap_feeds_drupal_user_attributes() {
74 79

  
75
  $attributes = array(
76
    'uid' => array('token' => 'drupal.uid', 'description' => 'Drupal used id.  e.g. 413'),
77
    'name' => array('token' => 'drupal.name', 'description' => 'Drupal username.  e.g. jdoe'),
78
    'mail' => array('token' => 'drupal.mail', 'description' => 'Drupal email address.  e.g. jdoe@gmail.com'),
79
    'created' => array('token' => 'drupal.created', 'description' => 'Drupal account created timestamp in unix e.g. 432432432'),
80
    'status' => array('token' => 'drupal.status', 'description' => 'Drupal user status  e.g. 1 or 0'),
81
    'language' => array('token' => 'drupal.language', 'description' => 'Drupal language.'),
82
    'signature' => array('token' => 'drupal.signature', 'description' => 'Drupal signature.  e.g. Happy Joe'),
83
    'login' => array('token' => 'drupal.login', 'description' => 'Drupal unix timestamp of last login  e.g. 1317494439'),
84
    'init' => array('token' => 'drupal.init', 'description' => 'Drupal user init  e.g. jdoe@gmail.com'),
85
  );
80
  $attributes = [
81
    'uid' => ['token' => 'drupal.uid', 'description' => 'Drupal used id.  e.g. 413'],
82
    'name' => ['token' => 'drupal.name', 'description' => 'Drupal username.  e.g. jdoe'],
83
    'mail' => ['token' => 'drupal.mail', 'description' => 'Drupal email address.  e.g. jdoe@gmail.com'],
84
    'created' => ['token' => 'drupal.created', 'description' => 'Drupal account created timestamp in unix e.g. 432432432'],
85
    'status' => ['token' => 'drupal.status', 'description' => 'Drupal user status  e.g. 1 or 0'],
86
    'language' => ['token' => 'drupal.language', 'description' => 'Drupal language.'],
87
    'signature' => ['token' => 'drupal.signature', 'description' => 'Drupal signature.  e.g. Happy Joe'],
88
    'login' => ['token' => 'drupal.login', 'description' => 'Drupal unix timestamp of last login  e.g. 1317494439'],
89
    'init' => ['token' => 'drupal.init', 'description' => 'Drupal user init  e.g. jdoe@gmail.com'],
90
  ];
86 91
  // ldap_authentication and some other modules may want to add additional drupal user tokens
87 92
  // largely derived from the $user->data array, but possibly from related data such as authmaps
88
  // some use cases for alter are simply edge cases
89

  
93
  // some use cases for alter are simply edge cases.
90 94
  drupal_alter('ldap_feeds_drupal_user_attributes', $attributes);
91 95

  
92 96
  return $attributes;
93 97
}
94 98

  
95 99
/**
96
 * show some sample ldap user data to help with mapping interface
100
 * Show some sample ldap user data to help with mapping interface.
97 101
 */
98

  
99 102
function ldap_feeds_form_feeds_ui_mapping_form_alter(&$form, &$form_state, $form_id) {
100 103

  
101 104
  $importer = feeds_importer_load($form['#importer']);
......
109 112
}
110 113

  
111 114
/**
112
 * add additional data to mapping form for ldap query fetcher
115
 * Add additional data to mapping form for ldap query fetcher.
113 116
 */
114 117
function ldap_feeds_query_legend(&$form, $importer) {
115 118

  
116 119
  $source = feeds_source($importer->id);
117 120
  $fetcher = feeds_plugin('FeedsLdapQueryFetcher', $source->importer->id);
118
 // $fetcher_result = new FeedsLdapQueryFetcher($source->config);
119
 // $records = $fetcher->getRaw(); // FeedsSource $source
120
 // foreach ($records[0] as $field_name => $value) {
121
  //  $sources[$field_name] = array(
122
  //    'name' => array('#markup' => $field_name),
123
   //   'description' => array('#markup' =>  _ldap_feeds_query_legend($records, $field_name)));
124
 // }
125
 // $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);
126
 // $form['legendset']['legend']['sources'] = $sources;
127

  
128 121
}
129 122

  
123
/**
124
 *
125
 */
130 126
function _ldap_feeds_query_legend($records, $field_name) {
131
  $examples = array();
127
  $examples = [];
132 128
  foreach ($records as $i => $record) {
133 129
    $examples[] = $record[$field_name];
134
    if ($i > 5 ) {
130
    if ($i > 5) {
135 131
      break;
136 132
    }
137 133
  }
138 134
  return join(', ', array_filter($examples));
139 135
}
136

  
140 137
/**
141
 * add additional data to mapping form for drupal user fetcher
138
 * Add additional data to mapping form for drupal user fetcher.
142 139
 */
143 140
function ldap_feeds_drupal_user_legend(&$form, $importer) {
144 141

  
145
  $sources = array();
142
  $sources = [];
146 143
  $servers = ldap_servers_get_servers(NULL, 'enabled');
147 144
  $form['legendset']['#description'] = "";
148 145
  $drupal_user_attributes = $importer->config['fetcher']['config']['availableDrupalUserAttributes'];
149 146

  
150 147
  foreach ($drupal_user_attributes as $attr_name => $attr_conf) {
151 148
    $id = $attr_conf['token'];
152
    $sources[$id] = array('name' => array('#markup' => $id), 'description' => array('#markup' => ''));
149
    $sources[$id] = ['name' => ['#markup' => $id], 'description' => ['#markup' => '']];
153 150
  }
154 151

  
155 152
  foreach ($servers as $sid => $ldap_server) {
......
162 159
        }
163 160
        $id = $attr_conf['token'];
164 161
        if ($account) {
165
          $sources[$id] = array('name' => array('#markup' => $id), 'description' => array('#markup' => $account->{$attr_name}));
162
          $sources[$id] = ['name' => ['#markup' => $id], 'description' => ['#markup' => $account->{$attr_name}]];
166 163
        }
167 164
      }
168 165

  
169 166
      $ldap_user = ldap_servers_get_user_ldap_data($ldap_server->testingDrupalUsername, $sid);
170 167
      foreach ($ldap_user['attr'] as $id => $value) {
171 168
        if (!is_numeric($id) && is_scalar($ldap_user['attr'][$id][0]) && $ldap_user['attr'][$id]['count'] == 1) {
172
          $sources[$id] = array('name' => array('#markup' => $id), 'description' => array('#markup' => $ldap_user['attr'][$id][0]));
169
          $sources[$id] = ['name' => ['#markup' => $id], 'description' => ['#markup' => $ldap_user['attr'][$id][0]]];
173 170
        }
174 171
        elseif ($ldap_user['attr'][$id]['count'] > 1) {
175 172
          $item = t('MULTIVALUED ATTRIBUTE:') . join(" , \n", $ldap_user['attr'][$id]);
176
          $sources[$id] = array('name' => array('#markup' => $id), 'description' => array('#markup' => $item));
173
          $sources[$id] = ['name' => ['#markup' => $id], 'description' => ['#markup' => $item]];
177 174
        }
178 175
      }
179 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
180
        the ldap server form.', array('%sid' => $sid, '%testing_user' => $ldap_server->testingDrupalUsername));
177
        the ldap server form.', ['%sid' => $sid, '%testing_user' => $ldap_server->testingDrupalUsername]);
181 178
    }
182 179
    else {
183
      foreach (array('dn' => 'distinguished name', 'cn' => 'cname') as $id => $value) {
184
        $sources[$id] = array('name' => array('#markup' => $id), 'description' => array('#markup' => $value));
180
      foreach (['dn' => 'distinguished name', 'cn' => 'cname'] as $id => $value) {
181
        $sources[$id] = ['name' => ['#markup' => $id], 'description' => ['#markup' => $value]];
185 182
      }
186 183
    }
187 184
  }

Formats disponibles : Unified diff